title: UIRefreshControl Crash App Parse.com Query
body: <p>I have a <code>UICollectionView</code> with a <code>UIRefreshControl</code>. The <code>UIRefreshControl</code> runs a query to get objects from Parse.com. When I perform the refresh by "pulling down" it causes the app to crash and display this message:</p>
  
  <pre><code>fatal error: Cannot index empty buffer
  </code></pre>
  
  <p>However when I press a button or in the <code>ViewDidLoad</code> to run the same refresh code it does not crash and performs the query as required. Does this mean that there is something wrong with the dragging rather than the refresh code?</p>
  
  <p>Here is the refresh code below (is it to do with the positioning of <code>self.refreshControl.endRefreshing()</code>?)</p>
  
  <pre><code>func refresh(sender:AnyObject)
  {
  
      println("Refresh")
  
      self.orderedIdArray = []
  
      self.idArray = []
      self.organizerNameArray = []
      self.categoryNameArray = []
      self.classNameArray = []
  
      var query = PFQuery(className:"Rides")
      query.orderByAscending("date")
      query.findObjectsInBackgroundWithBlock {
          (objects: [AnyObject]!, error: NSError!) -&gt; Void in
          if error == nil {
              // The find succeeded.
              NSLog("Successfully retrieved \(objects.count) scores.")
              // Do something with the found objects
  
  
              for object in objects {
                  NSLog("%@", object.objectId)
  
                  var testId = object.objectId
  
                  println(testId)
  
  
                  self.orderedIdArray.append(testId)
  
                  var query = PFQuery(className:"Rides")
                  query.getObjectInBackgroundWithId(testId) {
                      (gameScore: PFObject!, error: NSError!) -&gt; Void in
  
                      if error == nil {
  
  
  
                          NSLog("%@", gameScore)
  
                          //Gets the Values from Parse.com
  
                          self.organizerNameString = gameScore["organizer"] as String
  
                          self.categoryNameString = gameScore["category"] as String
  
                          self.classNameString = gameScore["class"] as String
  
                                  self.organizerNameArray.append(self.organizerNameString)
                                  self.categoryNameArray.append(self.categoryNameString)
                                  self.classNameArray.append(self.classNameString)
  
                                  self.idArray.append(object.objectId)
                                  NSLog("%@", self.idArray)
  
                              } else {
                                  println("Do not add to the array")
  
                              }
                      }   
                      } else {
                          NSLog("%@", error)
                      }
                      self.collectionView?.reloadData()
                  }
              }
  
          } else {
              // Log details of the failure
  
              NSLog("Error: %@ %@", error, error.userInfo!)
  
          }
          self.refreshControl.endRefreshing()
  
          NSLog("Ordered: %@", self.orderedIdArray)
      }
      println("Completed the query")
  
  }
  </code></pre>