在苹果文档中,要将 NSManagedObject 插入核心数据,我们需要这样做:
- (void)insertObject
{
NSMananagedObject *newObject = (UserInfo*)[NSEntityDescription insertNewObjectForEntityForName:@"myEntity" inManagedObjectContext:self.managedObjectContext];
[newObject setValue:@"aName" forKey:@"name"];
NSError *error = nil;
if (![context save:&error]) {
}
}
但是,如果我的 NSManagedObject 已经实例化,我该如何将它插入到核心数据上而不用重新实例化 'insertNewObjectForEntityForName:inManagedObjectContext' 并复制我的属性?
我想要这样的东西:
- (void)insertObject:(NSManagedObject*) newObject
{
//[newObject insertForEntity:@"entityName" forContext:context];
NSError *error = nil;
if (![context save:&error]) {
}
}