Aviav Sabag
Aviav Sabag

Reputation: 81

Closures(Swift) to closures(blocks?) in Objective-C

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 :)

Upvotes: 0

Views: 2032

Answers (1)

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19872

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);

Upvotes: 2

Related Questions