Created
December 21, 2016 03:11
-
-
Save josephchang10/119caf34e6d321a1233bad824b348ecb to your computer and use it in GitHub Desktop.
Core Data ManagedObjectContextSettable 协议
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ManagedObjectContextSettable: class { | |
var managedObjectContext: NSManagedObjectContext! { get set } | |
} |
最后,我们可以在应用程序代理给实现了这个协议的 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
现在我们让视图层次里的第一个 view controller 实现这个协议:
class RootViewController: UIViewController, ManagedObjectContextSettable { var managedObjectContext: NSManagedObjectContext! // ... }