title: iPhone Core Data saving conflict
body: <p>I am developing an application which upload number of photos and xml file in one attempt. I have two core data table with one-many(jobs &amp; photos) relation. One job may contain number of photos. Once all the photos has uploaded I need to upload xml file which contain photos details. I need to keep track on which photo has upload successfully and update the jobs table's status field as well as photo status. Following code illustrate that. </p>
  
  <p>This works some time. Some time this is not updating jobs table. I do appreciate is anyone can let me know what is wrong with following code.    </p>
  
  <pre><code>NSMutableArray *photosForJob=[[NSMutableArray alloc] initWithArray:[fetchedJob.photos allObjects]];    
  self.manageObjectForJobs = fetchedJob;
      __block int count = 0;
  
  dispatch_group_async(group, queue, ^{ 
  for (int i = 0; i &lt; [photosForJob count]; i++) 
  {
      Photos *ph = [photosForJob objectAtIndex:i];
  
      if ([ph.status compare:[NSNumber numberWithBool:NO]] == NSOrderedSame) 
      {                
          NSMutableArray *responseArray = [self filePosting:ph.photoName];                
          self.manageObjectForPhotos = ph;
  
          if ([[responseArray objectAtIndex:0] isEqual:@"200"] &amp;&amp; [[responseArray objectAtIndex:1] isEqualToString:ph.photoName]) 
          {
              [self.manageObjectForPhotos setValue:[NSNumber numberWithBool:YES] forKey:@"status"];                  
              count++;
          }                
      }
      else{
          count++;
      }            
  }
  
  if (count == [photosForJob count]) 
  {
      if ([status compare:[NSNumber numberWithBool:NO]] == NSOrderedSame) 
      {
  
          NSMutableArray *responseArray = [self filePosting:xmlFile];   
  
          if ([[responseArray objectAtIndex:0] isEqual:@"200"] &amp;&amp; [[responseArray objectAtIndex:1] isEqualToString:xmlFile]){
  
              [self.manageObjectForJobs setValue:[NSNumber numberWithBool:YES] forKey:@"status"];                    
          }
      }
  }
  
  NSError *error;
  if (![self.managedObjectContext save:&amp;error]) {            
      NSLog(@"Job status did updat.... : %@", [error description]);
  }
  else{            
      [UIApplication sharedApplication].applicationIconBadgeNumber = [self fetchJobsForBadge];
      [photosForJob removeAllObjects];
      count = 0;   
  }        
  });
  </code></pre>
  
  <p>Many Thanks</p>