Ano*_*ous 9 cocoa nsinvocation automatic-ref-counting
当我尝试将当前代码迁移到ARC时,每当我将NSString作为NSInvocation参数传递时,我都会收到错误.
例:
NSInvocation inv = ...;
NSString *one = @"Hello World!";
[inv setArgument:&one atIndex:2];
Run Code Online (Sandbox Code Playgroud)
当我使用编辑菜单中的重构 - >转换为Objective-C ARC选项时,会发生错误.文本是"NSInvocation的setArgument与不具有__unsafe_retained的所有权的对象一起使用是不安全的."
我怎么能绕过这个?
Abi*_*ern 10
这可能有用;
__unsafe_unretained NSString *one = @"Hello World";
Run Code Online (Sandbox Code Playgroud)
正如Joshua Weinberg评论的那样,不再推荐使用NSInvocation.如果您有最多两个参数,则可以使用performSelector.对于三个参数或更多,您可以使用NSObject的的-methodForSelector:作为解释在这里.
| 归档时间: |
|
| 查看次数: |
3689 次 |
| 最近记录: |