可能的重复:
PerformSelector 可能会导致泄漏,因为它的选择器未知 https://stackoverflow.com/questions/7017281/performselector-may-cause-a-leak-because-its-selector-is-unknown
我做了一个 NSDictionary 将我的输入(NSString)转换为选择器。 “选择器映射”如下所示:
[self setCmdSelectorMap:[NSDictionary dictionaryWithObjectsAndKeys:
[NSValue valueWithPointer:@selector(doOpenBrowserByString:)], @"openBrowser",
[NSValue valueWithPointer:@selector(syncData:)], @"sync",
[NSValue valueWithPointer:@selector(getCachedString:)], @"getCachedString",
nil]];
当我尝试获取这些选择器之一并按以下方式执行它时,它会导致警告:
sel = [[_cmdMap objectForKey:command] pointerValue];
NSLog(@"selector determined : %@", NSStringFromSelector(sel));
[self performSelector:sel withObject:arguments];
警告说: PerformSelector 可能会导致泄漏,因为它的选择器未知。有什么办法可以防止出现此警告吗?或者是否有任何“更安全”的方式来执行这样的操作?
多谢你们 :)
只需使用这个:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)