Skip to content

Instantly share code, notes, and snippets.

@tudormunteanu
Last active October 10, 2015 01:27
Show Gist options
  • Select an option

  • Save tudormunteanu/3610090 to your computer and use it in GitHub Desktop.

Select an option

Save tudormunteanu/3610090 to your computer and use it in GitHub Desktop.
some block examples
+ (void)iterateFromOneTo:(int)limit withBlock:(int (^)(int))block;
- (void) calculateLatestSpieltagWithCompletion:(void (^)(void))completion;
//
// Blocks as properties
//
typedef void(^MyCustomBlock)(void);
@interface MyClass : NSObject {
}
@property (nonatomic, copy) MyCustomBlock customBlock;
@end
@implementation MyClass
@synthesize customBlock;
- (void) dealloc {
[customBlock release];
[super dealloc];
}
@end
MyClass * c = [[MyClass alloc] init];
[c setCustomBlock:^{
NSLog(@"hello.....");
}];
[c customBlock](); //or c.customBlock()
[c release];
/*
Blocks as variables (can be used as properties)
*/
void (^instagramBlock)(void) = ^{
[self shareOnInstagram];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment