在Core Data中插入新的受管对象 [英] Inserting a new managed object in 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 inNSEntityDescription
. 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屋!