Here I am with another question.
As I was coding through my app, I'm using Parse Framework, and I'm using a query to obtain the username off the database:
var showUsername:PFQuery = PFUser.query()!
//showUsername.whereKey("objectId", equalTo: post.objectForKey("user")!.objectId)
showUsername.whereKey("objectId", equalTo: post.objectForKey("user")!)
showUsername.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil{
let user:PFUser = (objects as NSArray!).lastObject as! PFUser
cell.usernameLabel.text = user.username
}
}
I am having trouble with this two lines of code:
//showUsername.whereKey("objectId", equalTo: post.objectForKey("user")!.objectId)
this one I have it commented out because it says that with the .objectID is wrong, so if I take that out, it says it's fine. So I was wondering if the function of it would be the same???
And also, this line :
let user:PFUser = (objects as NSArray!).lastObject as! PFUser
It shows on Xcode that is correct, but when I run the app, it freezes and crashed because of that line of code due to the error that says that "[AnyObject]? is not convertible to 'NSArray'
any ways to work around this?
I already tried what this other links say:
"'[AnyObject]?' is not convertible to 'NSArray'"
"How to set the current user in cell? Swift, Parse"
And I get no errors in my code, and it runs, but the username is not changed to the actual username, it still says "Label"
unless it has to do with the query missing the .objectID?