Reputation: 45
Thanks to online tutorials I have been using core data with swift and iOS. To define a context I have used
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
How do I define the context when writing an OS X application?
Upvotes: 1
Views: 1061
Reputation: 47
You could also have done:
let context = (NSApplication.sharedApplication().delegate as AppDelegate).managedObjectContext
Upvotes: 0
Reputation: 1681
I define it that way:
lazy var context: NSManagedObjectContext? = {
let appDel = NSApplication.sharedApplication().delegate as! AppDelegate
if let moc = appDel.managedObjectContext {
return moc
} else {
return nil
}
}()
Upvotes: 1