在Core Data中插入新的受管对象 [英] Inserting a new managed object in Core Data

查看:155
本文介绍了在Core Data中插入新的受管对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Core数据的新手,我觉得我没有得到它。当你要创建一个新的托管对象,你必须使用我粘贴在底部从NSEntityDescription类的方法。



现在这个对象是在上下文中注册的,是对的吗?为什么在NSManagedContext中有 insertObject:?在使用 NSEntityDescription 中的方法后,它不会调用该方法。

  insertObject:

NSEntityDescription

  +(id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context 

解决方案

您可以使用 nil 上下文创建NSManagedObject,然后决定是否要添加到上下文或不上下文。
您可能也喜欢这样:有没有办法实例化NSManagedObject而不插入它?


I am new to Core Data and I feel that I don't get a hang of it. When you are going to create a new managed object you have to use the method that I pasted in at the bottom from the NSEntityDescription class.

Now is this object registered in the context, it is right? Why do you have the insertObject: in NSManagedContext then? It works without invoking that method after using the one in NSEntityDescription. Could somebody explain?

NSManagedContext

insertObject:

NSEntityDescription

+ (id)insertNewObjectForEntityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context

解决方案

You can create NSManagedObject with nil context and then decide whether you want to add it to context or not. You may also like this: Is there a way to instantiate a NSManagedObject without inserting it?

这篇关于在Core Data中插入新的受管对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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