可能重复:
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可能导致泄漏,因为它的选择器未知。有没有办法防止这种警告发生?或者是否有任何“更安全”的方式来执行此类行动?
谢谢你们:)
答案 0 :(得分:127)
请使用:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop