Last active
July 3, 2018 13:43
-
-
Save andriitishchenko/80ea48d720f24cfd5f4d9c0d525ff5fd to your computer and use it in GitHub Desktop.
NSInvocation VS objc_msgSend
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
Lets call the method: | |
- (void)document:(BAPreviewDocument*) doc shouldClose:(BOOL) shouldClose contextInfo:(void*) contextInfo; | |
Example of using NSInvocation | |
BOOL boolValue = YES; | |
NSMethodSignature * methodSig = [[delegate class] instanceMethodSignatureForSelector: shouldCloseSelector]; | |
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:methodSig]; | |
[invocation setTarget: delegate]; | |
[invocation setSelector: shouldCloseSelector]; | |
[invocation setArgument: &self atIndex: 2]; | |
[invocation setArgument: &boolValue atIndex: 3]; | |
[invocation setArgument: &contextInfo atIndex: 4]; | |
[invocation invoke]; | |
Example of using objc_msgSend | |
#include <objc/message.h> | |
void (*callback)(id, SEL, BAPreviewDocument *, BOOL, void *) = (void (*)(id, SEL, BAPreviewDocument *, BOOL, void *))objc_msgSend; | |
(*callback)(delegate, shouldCloseSelector, self, YES, contextInfo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment