1
我需要复制一个NSManagedObjectContext
中的现有对象图并将其插入第二个NSManagedObjectContext
。如何制作核心数据对象图的精确副本?
有没有简单的方法来做到这一点?从我可以告诉我可以要求商务部针对其-registeredObjects
,然后做这样的事情来复制属性:
NSString* entityName = [[sourceObject entity] name];
NSManagedObject* newObject = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:newMoc];
NSArray* attKeys = [[[sourceObject entity] attributesByName] allKeys];
NSDictionary* attributes = [sourceObject dictionaryWithValuesForKeys:attKeys];
[newObject setValuesForKeysWithDictionary:attributes];
不过,我不能确定如何在复制的关系。
确实,这听起来比我所搞的要容易得多。我会试一试,谢谢。 – 2009-10-16 05:21:31
完美的作品,非常感谢。 – 2009-10-16 05:53:45