ios Coredata large set insert
hey i am stuck with the same problem for days , time for insert increases
gradually and in lower ipads it also crashes with memory problem .To
insert 20k records it takes 4-5 minutes.Will background thread improve
efficieny. ? Is there anyway i can optimize this. Please help out if you
can.
+(BOOL) addObjectToProfessionalsDBWithDict:(NSArray*)profArray{
if (!([profArray count]>0 && profArray )) {
return NO;
}
NSManagedObjectContext *thisContext=[self getManagedObjectContext];
for (int i=0; i<[profArray count]; i++) {
NSManagedObject *professionalDBObject = [NSEntityDescription
insertNewObjectForEntityForName:@"ProfessionalsDB"
inManagedObjectContext:thisContext];//initWithDictionary:objectDict];
NSMutableDictionary *
objectDict=[profArray
objectAtIndex:i];
[professionalDBObject setValue:[objectDict valueForKey:@"Degree"]
forKey:@"degree"];
[professionalDBObject setValue:[objectDict valueForKey:@"First_Name"]
// and 10 more values
if(i%500==0){
NSError *error;
NSLog(@"saved rec nu %d",i);
if (![thisContext save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error
localizedDescription]);
return NO;
}
else{
NSLog(@"data saved");
}
[thisContext reset];
}
}
[prefs setInteger:numOfRecords forKey:@"numberOfRecords"];
NSError *error;
if (![thisContext save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
return NO;
}
return YES;
}
No comments:
Post a Comment