user1122069 user1122069 - 1 year ago 94
iOS Question

Is it possible to silence the warning on "performSelector" and receive the return value or object?

I am familiar with the solutions to this ARC warning (performSelector may cause a leak because its selector is unknown) and have implemented them in most cases, but I can't seem to find a way to properly get the return value for a selector without just suppressing a warning.

It seems that maybe it can't or shouldn't be done, but a rewrite of code logic (developed by others) is too time consuming.

Code example:

NSString *message = [callback performSelector:validatorSel withObject:textCell.textField.text];

Answer Source

If validatorSel is known to not to begin with allocor new, or to have copy (or Copy) in its name, and you know there are no memory-management overrides involved (which are rare), then the default memory management will be correct here, and you can suppress the warning with an appropriate #pragma. If you cannot prove those things, then this may crash, which is why there's a warning.

If you cannot prove the above requirements, then there is no way to make this safe under ARC. You will either have to build it without ARC or rewrite it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download