Skip to content

Instantly share code, notes, and snippets.

@samsonjs
Created September 12, 2014 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsonjs/3ddd991fa9c8a78da1d2 to your computer and use it in GitHub Desktop.
Save samsonjs/3ddd991fa9c8a78da1d2 to your computer and use it in GitHub Desktop.
welf
@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