我導入數據的量好到使用核心數據,像這樣我的應用程序:發佈對象添加到核心數據?
for (int i = 0; i < [items count]; i++)
{
Client *entity = (Client*) [NSEntityDescription insertNewObjectForEntityForName:@"Client" inManagedObjectContext:managedObjectContext];
[entity setCompanyName:[[items objectAtIndex:i] objectForKey:@"CompanyName"]];
//* bunch of other fields
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"%@",error);
}
}
我需要什麼,在這裏釋放?我應該做[實體發佈]嗎?
將上下文保存移到迭代循環外部,或將其保留在循環內部,但只能在「n」次迭代後保存。 (爲'n'選擇一個好的值將取決於平臺,Mac OS X與iOS) – ohhorob 2010-07-12 16:24:52