Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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 Cocoa应用程序-XCode 8和应用程序委托_Objective C_Cocoa_Xcode8_Appdelegate_Managedobjectcontext - Fatal编程技术网

Objective c Cocoa应用程序-XCode 8和应用程序委托

Objective c Cocoa应用程序-XCode 8和应用程序委托,objective-c,cocoa,xcode8,appdelegate,managedobjectcontext,Objective C,Cocoa,Xcode8,Appdelegate,Managedobjectcontext,在XCode 7中,我得到了如下managedObjectContext: [[[NSApplication sharedApplication] delegate] managedObjectContext] [[NSApplication sharedApplication] delegate] let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext 在XCode 8中,我

在XCode 7中,我得到了如下managedObjectContext:

[[[NSApplication sharedApplication] delegate] managedObjectContext]
[[NSApplication sharedApplication] delegate]
let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext
在XCode 8中,我在managedObjectContext上得到一个错误,它说:

未找到实例方法“managedObjectContext”

如何访问应用程序的managedObjectContext?

解决方案是:

AppDelegate* appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];

_managedObjectContext = [appDelegate managedObjectContext];
以及像这样调用应用程序代理的问题:

[[[NSApplication sharedApplication] delegate] managedObjectContext]
[[NSApplication sharedApplication] delegate]
let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext

在Swift中,您可以使用以下内容:

[[[NSApplication sharedApplication] delegate] managedObjectContext]
[[NSApplication sharedApplication] delegate]
let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext