在使用 performSelector: withObject: 函数出现“performSelector may cause a leak because its selector is unknown”。
主要是警告信息,在非ARC项目中没有这个警告。如果是在某一处修改只需要加入下列代码
[code=objc]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[vcappear performSelector:selector withObject:nil];
#pragma clang diagnostic pop
[/code]
如果在程序中多次使用可以设置一下宏
[code=objc]
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)
[/code]
如果没有返回值
[code=objc]
SuppressPerformSelectorLeakWarning(
[_target performSelector:_action withObject:self]
);
[/code]
有返回值
[code=objc]
id result;
SuppressPerformSelectorLeakWarning(
result = [_target performSelector:_action withObject:self]
);
[/code]