Iphone 是否将managedObjectContext注入初始viewController?

Iphone 是否将managedObjectContext注入初始viewController?,iphone,objective-c,core-data,uistoryboard,uimanageddocument,Iphone,Objective C,Core Data,Uistoryboard,Uimanageddocument,我正在我的AppDelegate中设置一个核心数据模型(UIManagedDocument),我想知道如何将对NSManagedObjectContext的引用插入到我的(故事板)初始viewController中 我可以使用[[[UIApplication sharedApplication]delegate]sampleDatabase]managedObjectContext]在viewControllersviewDidLoad中直接访问它,然后使用prepareForSegue将它传递

我正在我的AppDelegate中设置一个核心数据模型(
UIManagedDocument
),我想知道如何将对
NSManagedObjectContext
的引用插入到我的(故事板)初始viewController中

我可以使用[
[[UIApplication sharedApplication]delegate]sampleDatabase]managedObjectContext]
在viewControllers
viewDidLoad
中直接访问它,然后使用
prepareForSegue
将它传递给其他控制器


我只是想知道是否有一个初始序列(或机制)允许我通过(或注入)将managedObjectContext导入该初始viewController,而不必在控制器内部使用appDelegates共享实例访问它?

通常,您只需要在视图控制器上有一个NSManagedObjectContext属性,并在初始化视图控制器后立即设置该属性即可appDelegatemyViewController.managedObjectContext=self.managedObjectContext

使用情节提要时,在调用
应用程序:didFinishLaunchingWithOptions:
之前,初始视图控制器设置为代理的
rootViewController
属性

假设您的核心数据结构已经设置好,您应该能够对该引用使用强制转换来设置属性