第一种解决办法:
As a workaround until the compiler allows overriding the warning, you can use the runtime
objc_msgSend(_controller, NSSelectorFromString(@"someMethod"));
instead of
[_controller performSelector:NSSelectorFromString(@"someMethod")];
You'll have to
#import <objc/message.h>
第二种:
To ignore the error only in the file with the perform selector, add a #pragma as follows:
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
第三种:
#define SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING(code) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
code; \
_Pragma("clang diagnostic pop") \
SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING(
return [_target performSelector:_action withObject:self]
);

本文介绍了三种解决Objective-C中ARC与performSelector结合使用时产生的内存泄漏警告的方法,包括使用runtime objc_msgSend替代performSelector、忽略特定文件中的警告以及通过宏定义来抑制警告。
1151

被折叠的 条评论
为什么被折叠?



