1

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 ?

Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69

2 Answers2

1

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]
Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69
0

In Swift you would use something like this:

let context = (NSApplication.shared().delegate as! AppDelegate).managedObjectContext
Marc T.
  • 5,090
  • 1
  • 23
  • 40