Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id | title
- ============
- 1 | Foo
- 2 | Bar
- 3 | FooFoo
- NSError *saveError;
- [bookTwo setTitle:@"BarBar"];
- if (![managedObjectContext save:&saveError]) {
- NSLog(@"Saving changes to book book two failed: %@", saveError);
- } else {
- // The changes to bookTwo have been persisted.
- }
- NSError *error = nil;
- //This is your NSManagedObject subclass
- Books * aBook = nil;
- //Set up to get the thing you want to update
- NSFetchRequest * request = [[NSFetchRequest alloc] init];
- [request setEntity:[NSEntityDescription entityForName:@"MyLibrary" inManagedObjectContext:context]];
- [request setPredicate:[NSPredicate predicateWithFormat:@"Title=%@",@"Bar"]];
- //Ask for it
- aBook = [[context executeFetchRequest:request error:&error] lastObject];
- [request release];
- if (error) {
- //Handle any errors
- }
- if (!aBook) {
- //Nothing there to update
- }
- //Update the object
- aBook.Title = @"BarBar";
- //Save it
- error = nil;
- if (![context save:&error]) {
- //Handle any error with the saving of the context
- }
- bookTwo.title = @"BarBar";
- [bookTwo setValue:@"BarBar" forKey:@"title"];
Add Comment
Please, Sign In to add comment