Objective c Cocoa应用程序-XCode 8和应用程序委托
在XCode 7中,我得到了如下managedObjectContext: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中,我
[[[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