Created
January 29, 2014 02:22
-
-
Save westonplatter/8680680 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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