Ray*_*yer 34 macos objective-c ios
我做了一个NSDictionary来将我的输入(NSString)转换为选择器."选择器地图"看起来如下:
[self setCmdSelectorMap:[NSDictionary dictionaryWithObjectsAndKeys:
[NSValue valueWithPointer:@selector(doOpenBrowserByString:)], @"openBrowser",
[NSValue valueWithPointer:@selector(syncData:)], @"sync",
[NSValue valueWithPointer:@selector(getCachedString:)], @"getCachedString",
nil]];
Run Code Online (Sandbox Code Playgroud)
当我尝试获取其中一个选择器并按如下方式执行时,它会引发警告:
sel = [[_cmdMap objectForKey:command] pointerValue];
NSLog(@"selector determined : %@", NSStringFromSelector(sel));
[self performSelector:sel withObject:arguments];
Run Code Online (Sandbox Code Playgroud)
警告说:PerformSelector可能导致泄漏,因为它的选择器未知.有没有办法防止这种警告发生?或者是否有任何"更安全"的方式来执行此类操作?
多谢你们 :)
Ale*_*nov 128
只要用这个:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22192 次 |
| 最近记录: |