This code doesn’t involve compiler flags or direct runtime calls:

 

  1. SEL selector = @selector(zeroArgumentMethod);
  2. NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:selector];
  3. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig];
  4. [invocation setSelector:selector];
  5. [invocation setTarget:self];
  6. [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];


Resource
NSInvocation allows multiple arguments to be set so unlike performSelector this will work on any method.

And tip:

  1. #pragma clang diagnostic push
  2. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  3.     [self.ticketTarget performSelector: self.ticketAction withObject: self];
  4. #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