I need to execute a selector by name in the class (and not in the instance) and use its return value:
id obj = [objClass performSelector:NSSelectorFromString(methodName) withObject:p1];
The selector creates a new instance of the class. I need to use a return instance. Obviously, what I get is a regular performSelector that can cause a leak because its selector is unknown warning, because this project is compiled with ARC.
If I understood correctly ( from the answers here and others), in this case, the performSelector function will cause a leak (correct me if I am wrong, then I could just turn off the warning and do it). Selectors are implemented as follows:
+ (id) objectWithFile:(NSString*)p1 { return [NSKeyedUnarchiver unarchiveObjectWithFile:p1]; }
What are my options when I have to use a selector from a string, and the selector creates and returns a new instance of the object?
I considered NSInvocation, but its getReturnValue method requires me to provide my own dedicated buffer that stores the return value. I'm not sure if this even works with ARC and class methods, or just need __bridge_transfer to __bridge_transfer return buffer to id and all that it needs.
source share