title: NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL
body: <p>I am asking this question regarding my questions <a href="https://stackoverflow.com/questions/11545396/display-photolibrary-images-in-an-effectual-way-iphone">Display photolibrary images in an effectual way iPhone</a> and <em><a href="https://stackoverflow.com/questions/9135915/highly-efficiant-uitableview-cellforrowindexpath-method-to-bind-the-photolibra">Highly efficient UITableView "cellForRowIndexPath" method to bind the PhotoLibrary images</a></em>.</p>
  
  <p>So I would like to request that answers are not duplicated to this one without reading the below details :)</p>
  
  <p>Let's come to the issue,</p>
  
  <p>I have researched detailed about my above mentioned issue, and I have found the document about <strong>operation queues</strong> from <a href="http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>So I have created one sample application to display seven photo-library images using operation queues through ALAsset blocks.</p>
  
  <p>Here are the sample application details.</p>
  
  <p><strong>Step 1:</strong> </p>
  
  <p>In the NSOperationalQueueViewController <strong>viewDidLoad</strong> method, I have retrieved all the photo-gallery ALAsset <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator" rel="nofollow noreferrer">URLs</a> in to an array named <code>urlArray</code>.</p>
  
  <p><strong>Step 2:</strong>  </p>
  
  <p>After all the URLs are added to the <code>urlArray</code>, the  <strong>if(group != nil)</strong> condition will be false in <code>assetGroupEnumerator</code>, so I have created a <code>NSOperationQueue</code>, and then created seven UIImageView's through a <code>for</code> loop and created my <code>NSOperation</code> subclass object with the corresponding <strong>image-view</strong> and <strong>URL</strong> for each one and <strong>added</strong> them in to the <code>NSOperationQueue</code>.</p>
  
  <p>See my <code>NSOperation</code> subclass <a href="http://pastebin.com/MeYdde8h" rel="nofollow noreferrer">here</a>.</p>
  
  <p><strong>See my implementation (VierwController) class</strong> <a href="http://pastebin.com/aA3XkE7k" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Let's come to the issue.</p>
  
  <p>It not displaying all the seven images consistently. Some of the images are missing. The missing order is changing multiple times (one time it doesn't display the sixth and seventh, and another time it doesn't display only the second and third). The console log displays <strong>Could not find photo pic number</strong>. However, the URLs are logged properly.</p>
  
  <p>You can see the log details <a href="http://pastebin.com/b2wJGM6s" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Are there any mistakes in my classes?</p>
  
  <p>Also, when I go through the above mentioned <a href="http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html" rel="nofollow noreferrer">operational queue</a> documentation, I have read about <code>NSBlockOperation</code>. Do I need to implement <code>NSBlockOperation</code> instead of <code>NSOperation</code> while dealing with ALAsset blocks?</p>
  
  <p>The <code>NSBlockOperation</code> description says </p>
  
  <blockquote>
    <p>A class you use as-is to execute one or more block objects
    concurrently. Because it can execute more than one block, a block
    operation object operates using a group semantic; only when all of the
    associated blocks have finished executing is the operation itself
    considered finished.</p>
  </blockquote>
  
  <p>How can I implement the <code>NSBlockOperation</code> with ALAsset block regarding my sample application?</p>
  
  <p>I have gone through Stack Overflow question <em><a href="https://stackoverflow.com/questions/11009027/learning-nsblockoperation">Learning NSBlockOperation</a></em>. However, I didn't get any idea to implement the <code>NSBlockOperation</code> with ALAsset block!!</p>