title: Instance variable NSArray not updated correctly in Swift 2 - xCode 7.2
body: <p>My message object has a to, a from and a content variable. I'm creating a page to display a tableView with the unique conversation history. Meaning just names and profile pictures of the people he exchanged messages with. To do this I made a NSArray variable where I append the data in the loadData function to then display them on the table. My Parse query returns two objects, however when I print the resultData array count it prints 0 and the reloadData then of course doesn't work. However, adding a print statement line after I append a result object to the array in the loadData() function, that works and prints correctly twice which means the NSArray is just not updating. Anybody knows why?</p>
  
  <p>This is my code :</p>
  
  <pre><code>import Foundation
  import UIKit
  import Parse
  
  class MessagesController: UIViewController, UITableViewDataSource, UITableViewDelegate{
  
  
      @IBOutlet weak var loadingIndicator: UIActivityIndicatorView!
  
      @IBOutlet var tableView: UITableView!
  
      var resultData:NSMutableArray = NSMutableArray()
      var users = [String]()
  
      func loadData(){
  
  
          loadingIndicator.hidden = false
          loadingIndicator.startAnimating()
  
          resultData.removeAllObjects()
  
          var counter = 0
          let user = PFUser.currentUser()?.objectId
          let checkConversationsPredicate = NSPredicate(format: "(to = '\(user!)') OR (from = '\(user!)')")
          let checkConversationsQuery = PFQuery(className: "Messages", predicate: checkConversationsPredicate)
          checkConversationsQuery.findObjectsInBackgroundWithBlock { (objects, error) -&gt; Void in
              if let objects = objects {
                  for object in objects {
                      if (object.valueForKey("to") as? String) == user {
                          //check if from is in the list yet. If not, add him.
                          var isDuplicate = false
                          let from = object.valueForKey("from") as! String
                          for one in self.users {
                              if one == from {
                                  isDuplicate = true
                              }
                          }
  
                          //if it's not a duplicate add to our array of users
                          if !isDuplicate
                          {
                              let userQuery = PFUser.query()
                              userQuery?.whereKey("objectId", equalTo: object["from"] as! String)
                              userQuery?.findObjectsInBackgroundWithBlock({ (users, error ) -&gt; Void in
                                  if let users = users {
  
                                      for user in users{
                                          let followed = user as! PFUser
                                          self.resultData.addObject(followed)
                                          self.users.append(followed.objectId!)
                                          counter++
  
                                      }
                                  }
  
  
                              })
  
                          }
                      }
                      else {
                          //check if to is in the list yet, if not add him.
                          var isDuplicate = false
                          let to = object.valueForKey("to") as! String
                          for one in self.users {
                              if one == to {
                                  isDuplicate = true
                              }
                          }
  
                          //if it's not a duplicate add to our array of users
                          if !isDuplicate
                          {
                              let userQuery = PFUser.query()
                              userQuery?.whereKey("objectId", equalTo: object["to"] as! String)
                              userQuery?.findObjectsInBackgroundWithBlock({ (users, error ) -&gt; Void in
                                  if let users = users {
  
                                      for user in users{
                                          let followed = user as! PFUser
                                          self.resultData.addObject(followed)
                                          self.users.append(followed.objectId!)
                                          counter++
  
                                      }
                                  }
  
  
                              })
  
                          }
  
                      }
  
                  }
  
                   //reload data
                      print(self.resultData.count)
                      print(counter)
                      let array:NSArray = self.resultData.reverseObjectEnumerator().allObjects
                      self.resultData = NSMutableArray(array: array)
                      self.tableView.reloadData()
  
              }
  
  
              if counter == 0 {
                  //Handle no results
              }
          }
  
          loadingIndicator.hidden = true
          loadingIndicator.stopAnimating()
  
  
  
  
      }
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
      }
  
  
  
      override func viewDidAppear(animated: Bool) {
  
          self.loadData()
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  
            }
  
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          return resultData.count
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
  
          let cell:ConversationCell = tableView.dequeueReusableCellWithIdentifier("ConversationCell", forIndexPath: indexPath) as! ConversationCell
          let user:PFUser = self.resultData.objectAtIndex(indexPath.row) as! PFUser
  
          cell.profileId = user.objectId!
  
  
  
          let name = (user.objectForKey("firstName") as! String) + " " + (user.objectForKey("lastName") as! String)
          cell.name.text = name
  
          if user.objectForKey("profilePicture") != nil {
              if let profilePicture = user.objectForKey("profilePicture") as? PFFile {
                  profilePicture.getDataInBackgroundWithBlock({ (data, error) -&gt; Void in
                      if error == nil {
                          let profileImage = UIImage(data: data!)
                          cell.profilePicture.image = profileImage?.rounded?.circle
                      }
                  })
              }
          }
          else{
              cell.profilePicture.image = UIImage(named: "profile_picture_yellow.png")!.rounded?.circle
          }
  
  
  
  
  
          return cell
      }
  
  
      @IBAction func backButtonPressed(sender: AnyObject) {
          self.dismissViewControllerAnimated(true, completion: {});
      }
  
  }
  </code></pre>