2014-11-03 49 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