這裏是我的代碼,它正在採取一些JSON數據,並將其插入到核心數據房間實體:如何加快插入新的對象爲實體與核心數據
for (NSDictionary *room in rooms)
{
NSDictionary *thisroom = [room objectForKey:@"room"];
NSString *roomidstring = [thisroom objectForKey:@"roomid"];
int roomid = [roomidstring intValue];
NSString *roomname = [thisroom objectForKey:@"roomname"];
NSString *buildingidstring = [thisroom objectForKey:@"buildingid"];
int buildingid = [buildingidstring intValue];
// import into database
NSManagedObject *roomInfo = [NSEntityDescription insertNewObjectForEntityForName:@"room" inManagedObjectContext:context];
[roomInfo setValue:[NSNumber numberWithInteger:roomid] forKey:@"roomid"];
[roomInfo setValue:roomname forKey:@"roomname"];
[roomInfo setValue:[NSNumber numberWithInteger:buildingid] forKey:@"buildingid"];
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
}
插入約900時,這是令人難以置信的慢對象。有什麼辦法可以提高效率和/或加快速度嗎?
謝謝!
WOW,就像白天和黑夜。完成時間約爲15到20秒。謝謝! – asljkdfkjd