performSelector may cause a leak because its selector is unknown

后端 未结 19 2205
小蘑菇
小蘑菇 2020-11-22 01:54

I\'m getting the following warning by the ARC compiler:

\"performSelector may cause a leak because its selector is unknown\".

Here\'s what

19条回答
  •  迷失自我
    2020-11-22 02:43

    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];
    

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

提交回复
热议问题