Objective c NSWindowController中的EXC\u错误访问
好的,情况有点复杂,但是对于任何比我更熟悉内存管理的人来说,问题本身的性质应该非常简单 一些细节: -在我的主应用程序中,我正在加载一个“可加载”包(由一个Objective c NSWindowController中的EXC\u错误访问,objective-c,cocoa,automatic-ref-counting,nswindowcontroller,Objective C,Cocoa,Automatic Ref Counting,Nswindowcontroller,好的,情况有点复杂,但是对于任何比我更熟悉内存管理的人来说,问题本身的性质应该非常简单 一些细节: -在我的主应用程序中,我正在加载一个“可加载”包(由一个NSWindowController组成) -这两个项目(主应用程序和“插件”)都启用了ARC 在我的插件代码中,我有一个自定义初始化方法: - (id)initWithAPI:(id)api { pluginWindowController* newPluginWindowController = [super initWithWi
NSWindowController
组成)
-这两个项目(主应用程序和“插件”)都启用了ARC
在我的插件代码中,我有一个自定义初始化方法:
- (id)initWithAPI:(id)api
{
pluginWindowController* newPluginWindowController = [super initWithWindowNibName:@"PluginWindow"];
if (newPluginWindowController)
{
[newPluginWindowController setAPI:api];
}
return newPluginWindowController;
}
以下是API
的声明方式:
@property (unsafe_unretained) id API;
现在,这里有一个陷阱:
- 我正在使用
初始化,并且正在设置initWithAPI:
API
- 当我在
中测试-(void)windowDidLoad:
的值时,它仍然显示良好API
- 然而:当尝试在另一个方法中做同样的事情时(实际上是我的插件窗口中的按钮点击触发的IBAction)。。。试图获取
会触发[self-API]
错误EXC\u BAD\u ACCESS
我做错了什么?有什么想法吗?如果希望在对象死亡时自动将属性设置为
nil
,则将属性声明为weak
;如果希望对象保持活动状态,则将属性声明为strong
(strong
)
unsafe\u unrepaired
如果对象被解除分配,将导致指针悬空(这就是为什么它被称为“unsafe”。)