title: Parse query in ViewDidLoad for UICollectionViewController
body: <p>I'm trying to adapt the use of a UICollectionViewController I'm populating with an Array of local images to get the images from Parse.</p>
  
  <p>So far it's pretty straightforward. My NSArray is filled with the same local image many times:</p>
  
  <p>testImages = [NSArray arrayWithObjects: @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", nil];</p>
  
  <p>On the collectionView:cellForItemAtIndexPath: I do set up my cell (from Storyboard):</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      // Set up cell identifier that matches the Storyboard cell name
      static NSString *identifier = @"Cell";    
      UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
  
      // Configure the cell to show photo thumbnail
      UIImageView *testImageView = (UIImageView *)[cell viewWithTag:100];
  
      testImageView.image = [UIImage imageNamed:[testImages objectAtIndex:indexPath.row]];
  
      return cell;
  }
  </code></pre>
  
  <p>This is working and looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/EhTNr.jpg" alt="UICollectionViewController with array of local images"></p>
  
  <p>What I'm trying to do is to replace the locally created array from pictures that I get out of my Photo Class in Parse.</p>
  
  <p>I'm trying to do this on the viewDidLoad method:</p>
  
  <pre><code>PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
  
  PFUser *user = [PFUser currentUser];
  [query whereKey:@"user" equalTo:user];
  [query orderByAscending:@"createdAt"];
  [query setCachePolicy:kPFCachePolicyNetworkOnly];
  
  
  [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
      if (!error) {
          // The find succeeded.
          NSLog(@"Successfully retrieved %d photos.", objects.count);
          testImages = [NSMutableArray arrayWithArray:objects];
          NSLog(@"# Images: %d", [testImages count]);
  
          // Do something with the found objects
          for (PFObject *object in objects) {                
              NSLog(@"Object Name: %@", object.objectId);
          }
  
  
      } else {
          // Log details of the failure
          NSLog(@"Error: %@ %@", error, [error userInfo]);
      }
  }];
  </code></pre>
  
  <p>The thing is that I'm getting an empty array every time. I'm guessing that since this is getting executed on the block in the background once the collectionView:numberOfItemsInSection: asks for the count of elements on the "testImages" array I always get 0 elements.</p>
  
  <p>When the UICollectionViewController wants to use the information from the array to fill in the cells there's nothing there.</p>
  
  <p>I don't know if I'm placing my code in the wrong place or if I'm using the wrong query.</p>
  
  <p>Can you get my error here?</p>
  
  <p>Any feedback would be greatly appreciated.</p>