我有一个NSMutableArray,里面有几个NSManagedObjects,我是从我的managedObjectContext中获取的。 如何编辑managedObjects并用新的对象替换旧对象?
我从数组中取出这样的对象:
NSManagedObject *managedObject = [_dataArray objectAtIndex:indexToTest];
[managedObject setValue:@"sucessfully updated!" forKey:@"hint"];
我的问题是,如何更新managedObjectContext中的managedObject?
感谢您的帮助
答案 0 :(得分:1)
NSManagedObject * object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[object setValue:self.urlField.text forKey:@“url”];
NSManagedObjectContext * context = [self.fetchedResultsController managedObjectContext];
NSError *错误= nil;
if(![context save:& error]){}