I have some code that queries a class in my Parse database. But sometimes when I log in and get redirected to this view I get a "fatal error: Unexpectedly found nil while unwrapping an Optional value"
Here is my code:
let getPost = PFQuery(className: "Posts")
getPost.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
self.messages.removeAll(keepCapacity: true)
self.users.removeAll(keepCapacity: true)
self.usernames.removeAll(keepCapacity: true)
for object in objects {
self.messages.append(object["message"] as! String)
//////////THE LINE BELOW GIVES ME THE PROBLEM
self.usernames.append(self.users[object["userId"] as! String]!)
self.tableView.reloadData()
}
}
}
self.refresher.endRefreshing()
Anybody know what I've done wrong?