performSelector may cause a leak because its selector is unknown

后端 未结 19 2231
小蘑菇
小蘑菇 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:36

    If you don't need to pass any arguments an easy workaround is to use valueForKeyPath. This is even possible on a Class object.

    NSString *colorName = @"brightPinkColor";
    id uicolor = [UIColor class];
    if ([uicolor respondsToSelector:NSSelectorFromString(colorName)]){
        UIColor *brightPink = [uicolor valueForKeyPath:colorName];
        ...
    }
    

提交回复
热议问题