ios 防止出现“PerformSelect 可能导致泄漏,因为其选择器未知”的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10793116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
to prevent warning from "PerformSelect may cause a leak because its selector is unknown"
提问by Rayer
Possible Duplicate:
performSelector may cause a leak because its selector is unknown
I did a NSDictionary to convert my input(NSString) to selector. The "selector map" is looked as follows :
我做了一个 NSDictionary 将我的输入(NSString)转换为选择器。“选择器地图”如下所示:
[self setCmdSelectorMap:[NSDictionary dictionaryWithObjectsAndKeys:
[NSValue valueWithPointer:@selector(doOpenBrowserByString:)], @"openBrowser",
[NSValue valueWithPointer:@selector(syncData:)], @"sync",
[NSValue valueWithPointer:@selector(getCachedString:)], @"getCachedString",
nil]];
When I try to fetch one of these selector and perform it by follows, it cause a warning :
当我尝试获取这些选择器之一并按以下方式执行时,它会导致警告:
sel = [[_cmdMap objectForKey:command] pointerValue];
NSLog(@"selector determined : %@", NSStringFromSelector(sel));
[self performSelector:sel withObject:arguments];
The warning says : PerformSelector may cause a leak because its selector is unknown. Is there any way to prevent this warning from occurring? or is there any "safer" way to perform such an action?
警告说: PerformSelector 可能会导致泄漏,因为它的选择器未知。有什么办法可以防止这种警告发生吗?或者是否有任何“更安全”的方式来执行这样的操作?
Thanks guys :)
谢谢你们 :)
回答by Alexander Zakatnov
Just use this:
只需使用这个:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop