问题描述
在更新我的一些代码以与iOS 5 SDK兼容时,我试图通过在Xcode中使用转换为Objective-C ARC来重构我的代码并收到错误。我的.h文件中的实例变量发生错误。
In updating some of my code to be in compatible with the iOS 5 SDK, I attempted to refactor my code by using "Convert to Objective-C ARC" in Xcode and received an error. The error occurs on an instance variable in my .h file.
NSError **_error;
错误显示指向非const类型'NSError *',没有明确的所有权。我该如何解决这个问题?
The error says "Pointer to non-const type 'NSError *' with no explicit ownership." How might I fix this?
推荐答案
当存储 NSError
对象时实例变量你必须将它声明为一个简单的指针:
When storing NSError
objects in an instance variable you have to declare it as a simple pointer:
@interface Foo : NSObject
{
NSError *_errror;
}
NSError **
仅用于间接从方法返回 NSError
对象到调用者。将它存储在实例变量中(可能)是一个错误。
NSError **
is only used to indirectly return NSError
objects from a method to the caller. It is (probably) an error to store it in an instance variable.
这篇关于自动引用计数:指向非const类型“NSError *”的指针,没有明确的所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!