If I’m using ARC, how can I call the following method using performSelector: without leaking?
- (SomeClass *)test {
return [[SomeClass alloc] init];
}
If I use something like the following, I get a warning that I might introduce leaks, because ARC doesn’t know what to do, since the selector is generated programmatically.
[object performSelector:selector];
In this particular case, you’re fine. The warning is telling you that the compiler cannot tell if
-performSelector:is going to return a +0 or a +1 object, and the compiler will proceed with the assumption that it’s a +0 object. So whether or not you leak depends on the actual method called. In this case, your method is-test, which according to the naming rules returns a +0 object. So calling this method with-performSelector:will not leak.