Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSWindowController中的EXC\u错误访问_Objective C_Cocoa_Automatic Ref Counting_Nswindowcontroller - Fatal编程技术网

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”。)