Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data Import Failure
    primarykey
    data
    text
    <p>I'm trying to import a large data set (~6,000) in to my core data application. I've read the Apple document "Efficiently Importing Data" and I think I set it up correctly. The weird thing is the application isn't crashing in the simulator, although it does if I run it with the Leaks instrument, but it isn't saving all the data. Sometimes it will only save 3-4 hundred other times it will save 3-4 thousand and rarely the whole data set. I think it's probably memory leak related and I'm pretty new to using NSAutoReleasePool, any help would be much appreciated.</p> <pre><code> NSURL *url = [NSURL URLWithString:@""]; NSString *responseString = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil]; if (responseString) { NSArray *players = [responseString componentsSeparatedByString:@";"]; NSUInteger LOOP_LIMIT = 100, count = 0; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSManagedObjectContext *context = [[AppController sharedAppController] managedObjectContext]; [context setUndoManager:nil]; for (int i=0; i&lt;([players count] - 1); i++) { NSArray *info = [[players objectAtIndex:i] componentsSeparatedByString:@","]; NSString *dateInfo = [info objectAtIndex:10]; NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; NSDateFormatter *fo = [[[NSDateFormatter alloc] init] autorelease]; [fo setDateFormat:@"MM/dd/yyyy"]; [fo setLocale:usLocale]; [fo setTimeZone:[NSTimeZone systemTimeZone]]; NSDate *dob = [fo dateFromString:dateInfo]; Players *player = [NSEntityDescription insertNewObjectForEntityForName:@"Players" inManagedObjectContext:context]; NSNumberFormatter *f = [[[NSNumberFormatter alloc] init] autorelease]; [f setNumberStyle:NSNumberFormatterNoStyle]; player.playerID = [f numberFromString:[info objectAtIndex:0]]; player.lastName = [info objectAtIndex:1]; player.firstName = [info objectAtIndex:2]; player.position = [info objectAtIndex:4]; NSString *teamName = [info objectAtIndex:3]; NSFetchRequest *req = [[[NSFetchRequest alloc] init] autorelease]; NSEntityDescription *ent = [NSEntityDescription entityForName:@"Teams" inManagedObjectContext:context]; [req setEntity:ent]; [req setIncludesPropertyValues:NO]; NSPredicate *pre = [NSPredicate predicateWithFormat:@"team=%@", teamName]; [req setPredicate:pre]; NSArray *list = [context executeFetchRequest:req error:nil]; if ([list count]) { Teams *team = [list objectAtIndex:0]; player.team_Players_Teams = team; } count++; if (count == LOOP_LIMIT) { [context save:nil]; [context reset]; [pool drain]; pool = [[NSAutoreleasePool alloc] init]; count = 0; } } if (count != 0) { NSLog(@"In Save Remaining"); [context save:nil]; [context reset];[pool drain]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload