Created
July 7, 2015 14:26
-
-
Save teodorpatras/87f6b8918679043f62ba to your computer and use it in GitHub Desktop.
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
- (void) performSelectorAsync:(SEL) selector completion:(void(^)(id result))completion { | |
if ([self respondsToSelector:selector]) { | |
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ | |
//Background Thread | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:selector]]; | |
[invocation setSelector:selector]; | |
[invocation setTarget:self]; | |
__unsafe_unretained id unretainedResult = nil; | |
[invocation invoke]; | |
[invocation getReturnValue:&unretainedResult]; | |
id result = unretainedResult; | |
dispatch_async(dispatch_get_main_queue(), ^(void){ | |
//Main Thread | |
completion(result); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment