本文介绍了NSInvocation和ARC(自动引用计数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试将当前代码迁移到ARC时,每当将NSString作为NSInvocation参数传递时,都会收到错误消息.
When trying to migrate my current code to ARC, I'm getting errors whenever I pass an NSString as an NSInvocation argument.
示例:
NSInvocation inv = ...;
NSString *one = @"Hello World!";
[inv setArgument:&one atIndex:2];
当我使用编辑"菜单中的重构->转换为Objective-C ARC"选项时,会发生错误.文本为"NSInvocation的setArgument不安全用于拥有所有权不是__unsafe_retained的对象."
The error happens when I use the Refactor -> Convert to Objective-C ARC option from the Edit menu. The text is "NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_retained."
我该如何解决?
推荐答案
这可能有效;
__unsafe_unretained NSString *one = @"Hello World";
这篇关于NSInvocation和ARC(自动引用计数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!