Here is my viewDidLoad method -
var query = PFUser.query()
query.findObjectsInBackgroundWithBlock({ ( objects : [AnyObject]! , error: NSError! ) -> Void in
//self.users.removeAll(keepCapacity: true)
for object in objects {
var user:PFUser = object as PFUser
println(user.username)
self.users.append(user.username)
}
self.tableView.reloadData()
})
println( " Count \(users.count) ")
The count of users gets printed before the usernames in the users which makes me believe that it is taking time to fetch the users from the database. And for that reason my tableView never gets updated, the code for which looks like this -
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = users[indexPath.row]
return cell
Gives me an 'Array index out of range error' because the number of rows in my table is three while my dictionary is empty.
Couldn't find any particular solution on swift. Any suggestions?
EDIT : Forgot to mention that the users do get printed but after a long time (even after the count of the users which are being printed after the usernames are)
Just for the information, count is always printed as 1.
The output is something like this - Count 1 genaks genaks1427 genaks14271 adu afd