Created
June 22, 2013 06:03
-
-
Save jquave/5836050 to your computer and use it in GitHub Desktop.
This file contains 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
- (void)saveUserConsDetails:(NSArray*)userCons { | |
NSManagedObjectContext *moc = self.managedObjectContext; | |
NSMutableSet *usersConSet = [[NSMutableSet alloc] init]; | |
if ([NSNull null] != (id)userCons && 0 < [userCons count]) { | |
UserCon *userCon = nil; | |
NSString *userConId = nil; | |
for (NSDictionary* userConData in userCons) { | |
userConId = [userConData valueForKeyPath:@"UserCon._id"]; | |
NSLog(@"saveUserConsDetails: %@ with id %@", [userConData valueForKeyPath:@"User.firstname"], userConId); | |
userCon = [UserCon getUserConWithId:userConId withManagedObjectContext:moc]; | |
if (userCon) { | |
NSLog(@"usercon exists"); | |
[userCon setUserConDetails:[userConData valueForKeyPath:@"UserCon"]]; | |
} else { | |
NSLog(@"usercon new"); | |
userCon = [UserCon createWithDictionary:[userConData valueForKey:@"UserCon"] inManagedObjectContext:moc]; | |
} | |
User *user = [User getUserWithId:[userConData valueForKeyPath:@"User._id"] withManagedObjectContext:moc]; | |
if (user) { | |
NSLog(@"user exists"); | |
[user setUserDetails:[userConData valueForKey:@"User"]]; | |
} else { | |
NSLog(@"user does not exist"); | |
user = [User createWithDictionary:[userConData valueForKey:@"User"] inManagedObjectContext:moc]; | |
NSLog(@"created a user with name %@", user.firstname); | |
} | |
userCon.user = user; | |
NSLog(@"yes, we truly created a user in userCon called %@", userCon.user.firstname); | |
[usersConSet addObject:userCon]; | |
for(UserCon *uc in usersConSet) { | |
NSLog(@"added object.. heres all: user from con: %@", uc.user.fullName); | |
} | |
} | |
} | |
NSLog(@"user cons set from dict..."); | |
for(UserCon *uc in usersConSet) { | |
NSLog(@"user from con: %@", uc.user.fullName); | |
} | |
self.user_cons = usersConSet; | |
[usersConSet release]; | |
NSError *error; | |
[moc save:&error]; | |
for(UserCon *uc in self.user_cons) { | |
NSLog(@"user.user from con: %@", uc.user.fullName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment