Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON to Core Data SQLITE Error
    primarykey
    data
    text
    <p>Can anyone help figure out what i've done wrong within this code? trying to populate core data structure through JSON file</p> <pre><code>// Create the managed object context NSManagedObjectContext *context = managedObjectContext(); // Save the managed object context NSError *error = nil; if (![context save:&amp;error]) { NSLog(@"Error while saving %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error"); exit(1); } NSError* err = nil; NSString* dataPath = [[NSBundle mainBundle] pathForResource:@"Exercises" ofType:@"json"]; NSArray* Exercises = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:dataPath] options:kNilOptions error:&amp;err]; //NSLog(@"Imported Exercises: %@", Exercises); NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:context]; NSString *theJSONString = @"{\"key\":\"value\"}"; NSError *theError = NULL; NSDictionary *jsonDict = [NSDictionary dictionaryWithJSONString:theJSONString error:&amp;theError]; Exercise *exercise = [NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:context]; [Exercises enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSDictionary *attributes = [[object entity] attributesByName]; for (NSString *attribute in attributes) { id value = [jsonDict objectForKey:attribute]; if (value == nil) { continue; } [exercise setValue:value forKey:attribute]; } NSError *error; if (![context save:&amp;error]) { NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]); } }]; </code></pre> <p>Edited: Code now compiles but i get null values in the core data model. Thanks</p>
    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.
    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