Last active
August 29, 2015 14:23
-
-
Save YordiLorenzo/a64f89e9192fff3d4736 to your computer and use it in GitHub Desktop.
Shows Guide Core Data snippet
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) saveShow:(Show *)show { | |
| if (! [self exists:show]) { | |
| NSEntityDescription *entity = [NSEntityDescription entityForName:@"Show" inManagedObjectContext:self.managedObjectContext]; | |
| NSManagedObject *newShow = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext]; | |
| NSError *error; | |
| [newShow setValue:show.title forKey:@"title"]; | |
| [newShow setValue:[NSNumber numberWithLong:show.identifier] forKey:@"id"]; | |
| [newShow setValue:[NSNumber numberWithLong:show.seasonsCount] forKey:@"seasonsCount"]; | |
| [newShow setValue:[NSNumber numberWithLong:show.episodesCount] forKey:@"episodesCount"]; | |
| [newShow setValue:show.posterPath forKey:@"posterPath"]; | |
| [newShow setValue:show.overview forKey:@"overview"]; | |
| [newShow setValue:show.backdropPath forKey:@"backdropPath"]; | |
| [newShow setValue:show.airDate forKey:@"airDate"]; | |
| [newShow setValue:show.homepage forKey:@"homepage"]; | |
| if (![self.managedObjectContext save:&error]) { | |
| NSLog(@"Error saving new show"); | |
| return NO; | |
| } | |
| return YES; | |
| } | |
| return NO; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment