【发布时间】:2015-02-17 15:03:37
【问题描述】:
我正在使用 Core Data 提供离线支持。从外部 API 获取 JSON 响应,并在后台登录时将数据插入本地存储。导入检索 5000+ 条记录,大约需要 1.5 分钟。
这是我将数据插入本地数据库的代码。
- (void)insertProspectListDataInProspectTable:(NSMutableDictionary*)tempDict
{
int prospectID = [[tempDict valueForKey:@"ProspectID"] intValue];
Prospects *prospect = nil;
NSMutableArray *prospectListArray = [self isProspectAlreadyExistsWithProspectID:prospectID];
if ([prospectListArray count] > 0) {
prospect = [prospectListArray objectAtIndex:0];
}else {
prospect = (Prospects *)[NSEntityDescription insertNewObjectForEntityForName:PROSPECTS_ENTITY inManagedObjectContext:self.managedObjectContext];
}
//Prospect ID
[prospect setProspectID:[NSNumber numberWithInt:prospectID]];
//Subscriber Name
[prospect setSubscriberName:[tempDict valueForKey:@"SubscriberName"]];
//Attention
[prospect setAttention:(([tempDict valueForKey:@"Attention"] == [NSNull null] )?@"":[tempDict valueForKey:@"Attention"])];
//Email
[prospect setEMail:(([tempDict valueForKey:@"EMail"] == [NSNull null] )?@"":[tempDict valueForKey:@"EMail"])];
//Lead Date
NSString *leadDate = (([tempDict valueForKey:@"LeadDate"] == [NSNull null])?@"":[tempDict valueForKey:@"LeadDate"]);
[prospect setLeadDate:[GenricUI convertToMMDDYYYYFromYYYYMMDDFormate:leadDate]];
NSError *error;
if (![self.managedObjectContext save:&error]) {
// This is a serious error saying the record could not be saved.
// Advise the user to restart the application
}else {
// [self showSavedSuccessAlert];
}
}
我想提高我的应用程序的性能。有什么食谱吗?
【问题讨论】:
标签: ios objective-c json core-data bulkinsert