【发布时间】:2015-04-26 21:01:03
【问题描述】:
感谢在线教程,我一直在使用 swift 和 iOS 的核心数据。为了定义我使用的上下文
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
在编写 OS X 应用程序时如何定义上下文?
【问题讨论】:
感谢在线教程,我一直在使用 swift 和 iOS 的核心数据。为了定义我使用的上下文
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
在编写 OS X 应用程序时如何定义上下文?
【问题讨论】:
我是这样定义的:
lazy var context: NSManagedObjectContext? = {
let appDel = NSApplication.sharedApplication().delegate as! AppDelegate
if let moc = appDel.managedObjectContext {
return moc
} else {
return nil
}
}()
【讨论】:
你也可以这样做:
let context = (NSApplication.sharedApplication().delegate as AppDelegate).managedObjectContext
【讨论】: