Last active
October 10, 2015 01:27
-
-
Save tudormunteanu/3610090 to your computer and use it in GitHub Desktop.
some block examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (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