How to Write Objective-C Blocks
Since there are some ways to write Objective-C blocks, here are some snippets not to forget them.
Without artuments:
void (^block1)() = ^{
};
block1();
With some arguments:
NSInteger (^block2)(NSInteger, NSObject *) = ^(NSInteger arg1, NSObject *arg2) {
return arg1;
};
block2(0, nil);
With typedef
typedef void (^Block3)(id, NSError *);
typedef void (^Block4)(id response, NSError *error);
Block4 block4 = ^(id response, NSError *error) { };
With @property
@interface Object : NSObject
@property (nonatomic, copy) void (^block5)(id, NSError *);
@end
Written by Yuya
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Related Tags
#objective-c
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#