Query within query not appending with Swift/Parse
<p>I hope someone can help because this is probably a simple problem, but my Parse query within a query prints the object I am looking for, but cannot append it to the array I need it in to retrieve it in a UITableView.</p>

<p>The error is "fatal error: index out of range" when I dequeue the results of the query in a cell. </p>

<p>Here's the code:</p>

<p>import UIKit
import Parse
import Bolts</p>

<p>class MessagesTableVC: UITableViewController {</p>

<pre><code>var usernames = [String]()
var sentDate = [NSDate]()
var details = [String]()
var userImage = [PFFile]()


@IBAction func backToProfile(sender: AnyObject) {
    self.performSegueWithIdentifier("messagesToProfile", sender: self)
}


override func viewDidLoad() {
    super.viewDidLoad()

    let messagesQuery = PFQuery(className: "Messages")
    messagesQuery.whereKey("recipientId", equalTo: PFUser.currentUser()!.objectId!)
    messagesQuery.includeKey("senderId")
    messagesQuery.orderByDescending("createdAt")
    messagesQuery.findObjectsInBackgroundWithBlock({ (objects, error) -&gt; Void in

        if error != nil {
            print(error)
        }

        if error == nil {

            if let objects = objects {

                self.usernames.removeAll(keepCapacity: true)
                self.sentDate.removeAll(keepCapacity: true)
                self.details.removeAll(keepCapacity: true)
                self.userImage.removeAll(keepCapacity: true)

                for object in objects {

                    self.sentDate.append(object.createdAt! as NSDate)

                    if (object["item"] != nil) {
                    self.details.append(object["item"] as! String)
                    } else {
                    self.details.append(object["request"] as! String)
                    }

                    let senderObject = (object["senderId"] as! PFUser)
                    let senderId = (senderObject.objectId! as String)

                    print(senderId)

                    // Query for sender info
                    let userQuery = PFUser.query()
                    userQuery?.whereKey("objectId", equalTo: senderId)
                    userQuery?.getFirstObjectInBackgroundWithBlock({ (object, error) in

                        self.usernames.append((object!["username"] as! String))

                        //self.userImage.append(object!["profilePicture"] as! PFFile)

                    })




                }

                dispatch_async(dispatch_get_main_queue()) {
                    self.tableView.reloadData()
                    //self.search.resignFirstResponder()
                }
            }


    }
    })

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    // #warning Incomplete implementation, return the number of rows
    return sentDate.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("messageCell", forIndexPath: indexPath) as! MessageTableViewCell

    //print(usernames[indexPath.row])
    cell.senderUsername.text = usernames[indexPath.row]
    cell.itemOrPreview.text = details[indexPath.row]

    let date = sentDate[indexPath.row]
    let formatter = NSDateFormatter()
    formatter.dateStyle = NSDateFormatterStyle.LongStyle
    formatter.timeStyle = .ShortStyle
    let dateString = formatter.stringFromDate(date)
    cell.sentDate.text = dateString


    //userImage[indexPath.row].getDataInBackgroundWithBlock { (data, error) in
      //  if let downloadedItemImage = UIImage(data: data!) {
        //    cell.senderImage?.image = downloadedItemImage
        //}
    //}


    return cell
}

override func viewWillAppear(animated: Bool) {
    tableView.reloadData()
}
</code></pre>

<p>}</p>