title: iOS: How do I synchronize my managedObjectContext when using Grand Central Dispatch (GCD)?
body: <p>I'm using the following code to run a function that parses my xml files...</p>
  
  <pre><code>dispatch_queue_t queue = dispatch_queue_create("updateQueue", DISPATCH_QUEUE_CONCURRENT);
  
  dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file.xml"]; } ); 
  dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file1.xml"]; } );
  dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file2.xml"]; } );
  dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file3.xml"]; } );
  
  dispatch_barrier_async(queue,^ {
      dispatch_async(dispatch_get_main_queue(),^ { 
              [self setBottomBarToUpdated]; 
      });
  });
  </code></pre>
  
  <p>Here below is the function <code>updateFromXMLFile</code>:</p>
  
  <pre><code>- (BOOL) updateFromXMLFile:(NSString *)pathToFile {
  
           NSURL *url = [[NSURL alloc] initWithString:pathToFile];
           NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
  
           XMLParser *parser = [[XMLParser alloc] initXMLParser];
  
           parser.managedObjectContext = self.managedObjectContext;
  
           [xmlParser setDelegate: parser];
  
           BOOL success = [xmlParser parse];
  
           if(success)
                return TRUE;
           else
                return FALSE;
  
  }
  </code></pre>
  
  <p>The problem I'm coming across is this error message: <code>***Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection &lt;__NSCFSet: 0xc675e10&gt; was mutated while being enumerated.'</code></p>
  
  <p>I'm guessing that it has something to do with all the processes messing with my ManagedObjectContext at the same time. I'm not sure how to handle that though. Any ideas? Thanks!</p>