Created
September 12, 2014 17:06
-
-
Save samsonjs/3ddd991fa9c8a78da1d2 to your computer and use it in GitHub Desktop.
welf
This file contains 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
@interface AsyncAPI : NSObject | |
- (void)doSomethingForOwner:(__weak id)owner completionBlock:(void (^)(id welf, id result))complete; | |
@end | |
@implementation AsyncAPI | |
- (void)doSomethingForOwner:(__weak id)owner completionBlock:(void (^)(id welf, id result))complete { | |
[self doTheAsyncThing:^(id result) { | |
if (owner && complete) { | |
complete(owner, result); | |
} | |
}]; | |
} | |
- (void)doTheAsyncThing:(void (^)(id result))complete { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
complete(@42); | |
}); | |
} | |
@end | |
@interface MyClass : NSObject | |
- (void)frob; | |
@end | |
@implementation MyClass | |
- (void)frob { | |
AsyncAPI *api = [AsyncAPI new]; | |
[api doSomethingForOwner:self completionBlock:^(id welf, id result) { | |
[welf whatever]; | |
}]; | |
} | |
- (void)whatever {} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment