这里是我的代码,它正在采取一些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