title: Code in Objective-C c block not executed when expected
body: <p>I'm trying to read in EXIF data from images in the iOS camera roll using the fantastic code here: </p>
  
  <p><a href="http://blog.codecropper.com/2011/05/getting-metadata-from-images-on-ios/" rel="nofollow">http://blog.codecropper.com/2011/05/getting-metadata-from-images-on-ios/</a></p>
  
  <p>Unfortunately, on the first attempt to read the data, nil is returned ... but every subsequent attempt works fine. </p>
  
  <p>The author of the blog is aware of this and states a solution, but I just don't understand it at all! I'm new to "blocks" and I'm just not getting it even though I've read: <a href="http://thirdcog.eu/pwcblocks/" rel="nofollow">http://thirdcog.eu/pwcblocks/</a> </p>
  
  <p>Can anyone translate for me?</p>
  
  <p>This is the code being used to read in the data: </p>
  
  <pre><code>NSMutableDictionary *imageMetadata = nil;
  NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
  
  ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
  [library assetForURL:assetURL
  resultBlock:^(ALAsset *asset)  {
      NSDictionary *metadata = asset.defaultRepresentation.metadata;
      imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:metadata];
      [self addEntriesFromDictionary:metadata];
  }
  failureBlock:^(NSError *error) {
  }];
  [library autorelease];
  </code></pre>
  
  <p>which is conveniently put into an init method and called like: </p>
  
  <pre><code>NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithInfoFromImagePicker:info];
  </code></pre>
  
  <p>The authors description of the first attempt problem is: </p>
  
  <blockquote>
    <p>One caveat on using this: because it uses blocks, there’s no guarantee
    that your imageMetadata dictionary will be populated when this code
    runs. In some testing I’ve done it sometimes runs the code inside the
    block even before the [library autorelease] is executed. But the first
    time you run this, the code inside the block will only run on another
    cycle of the apps main loop. So, if you need to use this info right
    away, it’s better to schedule a method on the run queue for later
    with:</p>
  </blockquote>
  
  <pre><code>[self performSelectorOnMainThread:SELECTOR withObject:SOME_OBJECT waitUntilDone:NO];
  </code></pre>
  
  <p>.. and it's this line I'm stuck at! I don't know what to do with it?</p>
  
  <p>Any help greatly appreciated!</p>