Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Created January 29, 2014 02:22
Show Gist options
  • Select an option

  • Save westonplatter/8680680 to your computer and use it in GitHub Desktop.

Select an option

Save westonplatter/8680680 to your computer and use it in GitHub Desktop.
- (BOOL)loadJSON:(NSDictionary *)jsonDictionary
{
BOOL result = nil;
NSDictionary *userDictionary = [jsonDictionary valueForKey:@"user"];
NSString *userEmail = [userDictionary valueForKey:@"email"];
User *user = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.moc];
[user setEmail:userEmail];
NSArray *todos = [userDictionary valueForKey:@"todos"];
for (NSDictionary *todoDictionary in todos) {
Todo *todo = [NSEntityDescription insertNewObjectForEntityForName:@"Todo" inManagedObjectContext:self.moc];
if([todoDictionary valueForKey:@"action"]){
[todo setAction:[todoDictionary valueForKey:@"action"]];
}
if ([todoDictionary valueForKey:@"state"]) {
[todo setState:[todoDictionary valueForKey:@"state"]];
}
[todo setUser:user];
todo = nil;
}
NSError *error = nil;
result = [self.moc save:&error];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment