Cocoa Application - XCode 8 and App Delegate

261 Views Asked by At

In XCode 7, I got the managedObjectContext like this:

[[[NSApplication sharedApplication] delegate] managedObjectContext]

in XCode 8 I get an Error over the managedObjectContext saying:

Instance method 'managedObjectContext' not found;

How do I get to the App's managedObjectContext ?

2

There are 2 best solutions below

0
On

In Swift you would use something like this:

let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext
0
On

The solution was:

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

_managedObjectContext = [appDelegate managedObjectContext];

And the problem with with the calling the App Delegate like this:

[[NSApplication sharedApplication] delegate]