0

Hi guys Im kinda new to Objective-C and I've got a little code that I would like to convert it from Swift -> Objective-C. I've got a variable which is a closures but not sure how doing it in Objective-C Here's the variable:

var didTimerFire: ((UICollectionViewCell) -> Void)? 

also is there's any "self" in objective-C? sorry for being a noob but again kinda new to Objective-C :)

1

1 Answer 1

2

In Objective-C there are Blocks:

If you want to use them as property it goes like:

@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);

Or as method parameters:

- (void)method:(returnType (^nullability)(parameterTypes))blockName;

So for you example it will go like:

@property (nonatomic, copy, nullable) void (^didTimerFire)(UICollectionViewCell);

Sign up to request clarification or add additional context in comments.

4 Comments

Got ya :) btw is there any "Self" in Objective-C as Swift has? :)
I have written a LOT of Objective-C, and I never did memorize the hideous block syntax. The way you specify a property, a method parameter, and a block type are all different and non-intuitive. There is a link I bookmarked called fuckingblocksyntax.com. I suggest referring to that.
@Grzegorz Krukowski btw how to use it like this in objective-c : cell.didTimerFire = { [weak self] cell in guard let self = self else { return } self.impressionEventStalker?.stalkCells() } like completion handler
I seem to remember there being a G rated version of the page with exactly the same content. I hesitated to link it, given the off-color name, but it certainly captures my (and others', obviously) feelings about Objective-C block syntax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.