「performSelector may cause a leak because its selector is unknown」ソリューション

4377 ワード

Because you're dynamically assigning  action , the compiler sees a possible leak with ARC. In the future, the LLVM compiler may allow you to suppress the warning. Until then, you can avoid the warning by using the runtime's  objc_msgSend()  instead of  -performSelector: .
First, import the runtime message header
#import <objc/message.h>

Next, replace performSelector: with objc_msgSend()
 
 // [object performSelector:action]; objc_msgSend(object, action);

 
またはwarning禁止
 
In the LLVM 3.0 compiler in Xcode 4.2 you can suppress the warning as follows:
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [object performSelector:action]; #pragma clang diagnostic pop

Thanks to Scott Thompson (about this similar question:  performSelector may cause a leak because its selector is unknown ) for the answer.