Skip to content

Instantly share code, notes, and snippets.

@YordiLorenzo
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save YordiLorenzo/a64f89e9192fff3d4736 to your computer and use it in GitHub Desktop.

Select an option

Save YordiLorenzo/a64f89e9192fff3d4736 to your computer and use it in GitHub Desktop.
Shows Guide Core Data snippet
- (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