I am trying to have a fairly dynamic api for the level class of my game… basically, I just have a bunch of class methods optionsForLevel1, optionsForLevel2, …etc, that all return a dictionary object with things like how much time the level should have, how many bonus points, the level’s name, etc…
In my actual game object, when it’s time to advance levels, it calls a method on the level object which does:
+(NSDictionary*)performClassSelectorForLevel:(int)identifier {
SEL sel = NSSelectorFromString([NSString stringWithFormat:@"optionsForLevel%d", identifier]);
return [self performSelector:sel];
}
This gives me a warning: PerformSelector may cause a leak because its selector is unknown.
…
How can I resolve this warning?
This is interesting. You can’t. Not in my experience. Simply this is a warning, not an error, this “may” cause a leak.
When using
performSelector:it’s your responsibility to make sure it doesn’t leak, of course the compiler doesn’t know the selector in theNSString, it’s unknown at compile time, as it will have its value assigned at runtime.You can suppress this warning, but it’s okay to ignore
Check out this answer for more details: PerformSelector warning