Skip to content

Instantly share code, notes, and snippets.

@josephchang10
Created December 21, 2016 03:11
Show Gist options
  • Save josephchang10/119caf34e6d321a1233bad824b348ecb to your computer and use it in GitHub Desktop.
Save josephchang10/119caf34e6d321a1233bad824b348ecb to your computer and use it in GitHub Desktop.
Core Data ManagedObjectContextSettable 协议
protocol ManagedObjectContextSettable: class {
var managedObjectContext: NSManagedObjectContext! { get set }
}
@josephchang10
Copy link
Author

最后,我们可以在应用程序代理给实现了这个协议的 root view controller 设置上下文对象:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // ... guard let vc = window?.rootViewController as? ManagedObjectContextSettable else { fatalError("Wrong view controller type") } vc.managedObjectContext = managedObjectContext // ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment