0
NSInvocation alternative for performSelector:
This code doesn’t involve compiler flags or direct runtime calls:
- SEL selector = @selector(zeroArgumentMethod);
- NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:selector];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig];
- [invocation setSelector:selector];
- [invocation setTarget:self];
- [invocation invoke];
SEL selector = @selector(zeroArgumentMethod); NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:selector]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig]; [invocation setSelector:selector]; [invocation setTarget:self]; [invocation invoke];
ResourceNSInvocation allows multiple arguments to be set so unlike performSelector this will work on any method.
And tip:
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
- [self.ticketTarget performSelector: self.ticketAction withObject: self];
- #pragma clang diagnostic pop
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.ticketTarget performSelector: self.ticketAction withObject: self];
#pragma clang diagnostic pop

Recent Comments