核心数据:受管对象和实体之间的差异? [英] core data : differences between managed object and entities?

查看:200
本文介绍了核心数据:受管对象和实体之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解更多的核心数据,为什么我们抓取和搜索实体,而实体是内部管理对象?例如:

i would like to understand a bit more Core Data, why do we "fetch" and search for entities while the entities are "inside" managed objects? For example :

NSManagedObjectContext *moc = [self managedObjectContext];  
NSEntityDescription *entityDescription =
    [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:moc];  
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];  
[request setEntity:entityDescription];

还有,持久化对象存储包含什么?如果我明白了,持久化对象存储从一个sqlite文件中获取数据,但是它得到一个困惑,是它:一个实体,对于一个持久化对象存储,对于sqlite文件中的一个数据?

also, what does a persistent object store contain? if i understood, the persistent object store takes data from a sqlite file, but then it gets a bit confused, is it : one entity, for one persistent object store, for one data inside the sqlite file?

感谢您的回答

Paul

推荐答案

这里基本上有5个组件。持久存储协调器,受管对象上下文,受管对象模型,实体和受管对象。他们都一起工作,提供一个对象图管理系统(注意,核心数据一个ORM,所以它帮助不这样想)。下面是CoreData中与它们交互的组件和其他类的描述。

Basically there are 5 components here. A persistent store coordinator, a managed object context, a managed object model, entities and managed objects. They all work together to provide an object graph management system (note that Core Data is not an ORM so it helps not to think of it that way). Below is a description of the components and the various other classes in CoreData that interact with them


  • NSPersistentStoreCoordinator - 处理从磁盘加载数据。它处理各种商店( NSPersistentStore )。包括的商店类型是二进制,XML和SQLite。您可以编写自己的商店(使用 NSAtomicStore NSIncrementalStore 类),例如,如果您有自己的文件类型(理论上你可以写一个商店打开Word或Photoshop文件,如果你想要的话)

  • NSEntityDescription 被认为是一个被管理对象的类。它定义了任何属性( NSAttributeDescription ),关系( NSRelationshipDescription )和获取的属性( NSFetchedPropertyDescription )应该使用的子类,以及应该使用的 NSManagedObject 子类的其他属性

  • NSManagedObjectContext - 这是内存中的暂存区。它是你查询对象的地方(使用 NSFetchRequests ),创建对象,删除对象等。你可以有多个上下文,抛出一个而不保存丢弃任何更改

  • NSManagedObject - Core Data的核心单元。这些是保存数据的模型对象。

  • NSManagedObjectModel - 这表示用于数据的数据模型,通常在Xcode中创建的.mom文件中定义。这是所有实体都存储的地方。

  • NSPersistentStoreCoordinator - This handles the loading of data to and from disk. It deals with various stores (NSPersistentStore). The included store types are binary, XML and SQLite. You can write your own stores (using the NSAtomicStore and NSIncrementalStore classes), for example if you have your own file type (theoretically you could write a store to open a Word or Photoshop file if you desired)
  • NSEntityDescription - An entity can be sort of thought of as the "class" of a managed object. It defines any attributes (NSAttributeDescription), relationships (NSRelationshipDescription) and fetched properties (NSFetchedPropertyDescription) that a managed object should have, as well as other properties such as the NSManagedObject subclass that should be used
  • NSManagedObjectContext - This is the in memory "scratch pad". It is where you query for objects (using NSFetchRequests), create objects, delete objects etc. You can have multiple contexts, and throw one away without saving to discard any changes you no longer need.
  • NSManagedObject - The core unit of Core Data. These are your model objects that hold your data. You set the attributes, relationships etc on them.
  • NSManagedObjectModel - This represent the data model to use for your data, which is usually defined in a .mom file created within Xcode. This is where all the entities are stored.

这几乎是整个核心数据。还有一些其他类用于迁移和合并

That's pretty much the whole of core data. There are some other classes for doing migrations and merging

这篇关于核心数据:受管对象和实体之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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