防止警告“PerformSelect可能导致泄漏,因为它的选择器未知” [英] to prevent warning from "PerformSelect may cause a leak because its selector is unknown"
本文介绍了防止警告“PerformSelect可能导致泄漏,因为它的选择器未知”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了一个NSDictionary来将我的输入(NSString)转换为选择器。 选择器映射如下所示:
I did a NSDictionary to convert my input(NSString) to selector. The "selector map" is looked as follows :
[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];
警告说:PerformSelector可能导致泄漏,因为它的选择器未知。有没有办法防止这种警告发生?或者有没有更安全的方式来执行这样的行动?
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?
谢谢你们:)
推荐答案
只需使用:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop
这篇关于防止警告“PerformSelect可能导致泄漏,因为它的选择器未知”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文