title: NSManagedObjectContext and performBlock, changes on iOS 8?
body: <p>I have an old project (started on iOS 7) with this simple code:</p>
  
  <p>in AppDelegate I create the managedObjectContext:</p>
  
  <pre><code>- (NSManagedObjectContext *)managedObjectContext {
      // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
      if (_managedObjectContext != nil) {
          return _managedObjectContext;
      }
  
      NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
      if (!coordinator) {
          return nil;
      }
      _managedObjectContext = [[NSManagedObjectContext alloc] init];
      [_managedObjectContext setPersistentStoreCoordinator:coordinator];
      return _managedObjectContext;
  }
  </code></pre>
  
  <p>Then, I perform an update operation in a view controller:</p>
  
  <pre><code>    [context performBlock:^{
          [context deleteObject:anObject];
  
          NSError *error = nil;
          if (![context save:&amp;error])
          {
              NSLog(@"Error saving context");
          }
      }];
  </code></pre>
  
  <p>I'm sure that this code was working correctly on iOS 7.0, but crashes on the <code>performBlock:</code> call on iOS 8 with this error: </p>
  
  <blockquote>
    <p>Can only use -performBlockAndWait: on an NSManagedObjectContext that was created with a queue.</p>
  </blockquote>
  
  <p>I can solve the error changing the init method of the NSManagedObjectContext instance like this:</p>
  
  <pre><code>_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
  </code></pre>
  
  <p>But I don't understand why this behavior changed. In the documentation of NSManagedObjectContext you can read:</p>
  
  <blockquote>
    <p>A consequence of this is that a context assumes the default owner is the thread or queue that allocated it—this is determined by the thread that calls its init method.</p>
  </blockquote>
  
  <p>So, in my first example, using a simple <code>init</code> call, the queue owner of the context is the main thread.
  The <code>performBlock:</code> call was made on the main thread too, so I don't understand why this error. Am I missing something or it's a bug in iOS 8?</p>