2014-11-03 90 views
0

我开发了具有核心日期的iOS应用程序。我有下表。核心数据 - 所有记录的特定列更新

id | title  | Value 
=========================== 
    1 | Foo   | 100 
    2 | Bar   | 200 
    3 | FooFoo  | 300 

现在我想更新的所有记录值列是500

我使用下面的代码,

NSArray *mutableFetchResult = [[[self.managedObjectContext  executeFetchRequest:fetchRequest error:&error] mutableCopy] autorelease]; 
if (mutableFetchResult == nil) { 
    NSLog(@"Fetch result error %@, %@", error, [error userInfo]); 
} 
for (NSManagedObject *ob2 in mutableFetchResult) 
{ 
    [newContact setValue:@“500” forKey:@"Value"]; 
    if (![context save:&error]) { 
      NSLog(@"Failed to save - error: %@", [error localizedDescription]); 
    } 
} 

它的工作原理fine.But我不想使用for循环来更新记录。在我担心的我有大约60000条记录。所以它看起来有点奇怪。

任何帮助将大大appreciated.Thanks

回答

1

在iOS中8,您可以使用NSBatchUpdateRequest做一个批处理请求。恐怕,您将不得不遍历每条记录以更新iOS 7

阅读批量更新,在这个美丽教程:

Batch Update in Core Data

+0

感谢answer.I现在用NSBatchUpdateRequest.But有没有其他替代了iOS6的&7? – Thangavel 2014-11-03 13:46:24