Automatic Reference Counting: Pointer to non-const type #39;NSError *#39; with no explicit ownership(自动引用计数:指向非 const 类型“NSError *的指针,没有明确的所有权)
问题描述
在更新我的一些代码以与 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 *"的指针,没有明确的所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自动引用计数:指向非 const 类型“NSError *"的指
基础教程推荐
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
