0
votes

I'm getting the following warning by the ARC compiler

performSelector may cause a leak because its selector is unknown

This is my code:

[self performSelector:config.selector];

Why do I get this warning? I understand the compiler can't check if the selector exists or not, but why would that cause a leak? And how can I change my code so that I don't get this warning anymore?

1
Please search on errors before posting.rmaddy
@rmaddy is correct; this is a dupe of stackoverflow.com/questions/7017281/…bbum
@bbum If it's a dupe, why did you reopen?rmaddy
@rmaddy A misguided attempt to provide a modern answer.bbum

1 Answers

0
votes

As @rmaddy points out, this is a duplicate of performSelector may cause a leak because its selector is unknown


There is a better solution than either suppressing the warning or playing other games.

Instead of using the SEL, use callback blocks instead.

I.e. instead of config.selector, go for config.handlerBlock(...).

That way, you have full type safety throughout, nothing gets in the way of using ARC, and no #pragma dance to disable warnings temporarily or anything.