title: CoreData could not fulfill a fault for when objects are updated by HTTP service
body: <p>I think I understand the error message: CoreData could not fulfill a fault, but I am not sure how I should deal with it.</p>
  
  <p>We have an application where we use Core Data to persist data returned from a JSON service. Today I am doing the following.</p>
  
  <ol>
  <li>Fetch local object from persistent store and return to UI</li>
  <li>Ask server if the object is updated - when I get the answer, I update the Core Data managed object</li>
  <li>Update UI with the updated object</li>
  </ol>
  
  <p>The problem is; even if I do not use multi threads I sometimes gets an error when the HTTP request deletes managed objects that my UI has retained. I tried to fetch the objects with returnsObjectsAsFaults to NO. I thought I then could access all the relations and properties of an managed object even if it was deleted (as long as my UI had retained it).</p>
  
  <p>How should I solve this issue?</p>
  
  <p>I thought I could use separate NSManagedObjectContext for read and write. I have made this test:</p>
  
  <pre><code>MyAuthorMO *authorUpdate = [[MyAuthorMO alloc] init]; // I have made this init insert the object into the updateContext
  authorUpdate.firstname = @"Hans";
  authorUpdate.lastname = @"Wittenberg";
  authorUpdate.email = @"Hans@somedomain.no";
  
  NSManagedObjectContext *updateContext = [[MyCoreManager getInstance] managedObjectContext];
  
  NSError *error = nil;
  [updateContext save:&amp;error];
  
  NSManagedObjectContext *readContext = [[MyCoreManager getInstance] readOnlyContext];
  
  NSFetchRequest *fetchRequest = [managedObjectModel fetchRequestFromTemplateWithName:@"authorByEmail" substitutionVariables:[NSDictionary dictionaryWithObject:@"Hans@somedomain.no" forKey:@"EMAIL"]];
  [fetchRequest setReturnsObjectsAsFaults:NO];
  
  NSArray *authors = [readContext executeFetchRequest:fetchRequest error:&amp;error];
  
  MyAuthorMO * readAuthor = [authors objectAtIndex:0];
  
  // Delete the author with update context:
  [updateContext deleteObject:authorUpdate];
  [updateContext save:&amp;error];
  
  NSLog(@"Author: %@ %@, (%@)", readAuthor.firstname, readAuthor.lastname, readAuthor.email);
  </code></pre>
  
  <p>The log is outputted just fine as long as I use the readContext for the fetch. If I use the updateContext for the fetch, I get an exception. This looks promising, but I am afraid that I will run into problems at a later stage. Sooner or later I will probably try to access a property that is not fetched completely (a fault). How can I achieve the behaviour I am looking for? </p>