核心数据 - 基本问题 [英] Core Data - Basic Questions

查看:92
本文介绍了核心数据 - 基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道以下是如何在Objective-C

I would like to know how the following works in Objective-C


  1. 在我的头文件中有以下从不同的视图控制器初始化

  1. in my header file i have the following which is initialized from a different view controller

@interface UserLookup : UIViewController {
    NSManagedObjectContext *referringObject;
}


文件我必须通过这个 NSManagedObjectContext 到2个子视图控制器,然后它做一个区别,首先调用视图控制器...和 NSManagedObjectContext

and in my implementation file i have to pass this NSManagedObjectContext to 2 child view controller then does it make a difference which view controller is called first... and does the NSManagedObjectContext changes in any one of the child controller?

尊敬

推荐答案

你真的不需要传递给每个视图控制器,你需要核心数据访问 - 只需使用

You don't really need to pass it around to every view controller where you will need Core Data access - just use

NSManagedObjectContext* moc = [(MyAppDelegateClass *)[[UIApplication sharedApplication] delegate] managedObjectContext];

managedObjectContext 必须是app delegate。

managedObjectContext must be an accessible ivar of your app delegate.

这在概念上也是类似的。有一个NSManagedObjectContext(在最简单的应用程序,认为你可以有多个),由您的应用程序委托拥有。你不会保留或释放它(除了当它在应用程序委托创建时,首次访问时如果你使用的是Apple的模板代码,当它在应用程序委托的 dealloc

It makes it conceptually similar too. There is one NSManagedObjectContext (in most uncomplicated apps, thought you can have multiples), owned by your app delegate. You don't ever retain or release it (except for when it is created in the app delegate, on first access if you are using Apple's template code, and when it is released in app delegate's dealloc.

这篇关于核心数据 - 基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆