Mason Ballowe
Mason Ballowe

Reputation: 1866

New Parse forces "optional", how to query a PFUser?

I have this code that due to the x-code changes is no longer working.

    var query = PFUser.query()
    var user = PFUser.currentUser()!.username
    query!.whereKey("username", equalTo: "\(user)")
    query!.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil {

The problem is that the PFUser.currentUser()!.username aka, the "user" variable now prints out the following : Optional("username")

Therefore, it searches for a username with the text: Optional("") and a username between the quotes.

So it doesn't find a username.

Ever since the last x-code update, the query is requiring this optional crap.

Upvotes: 0

Views: 666

Answers (1)

Mason Ballowe
Mason Ballowe

Reputation: 1866

got it to work.

    var query = PFUser.query()
    query!.whereKey("username", equalTo: PFUser.currentUser()!.username!)
    query!.findObjectsInBackgroundWithBlock {

added a ! after username in PFUser.currentUser()!.username!

Upvotes: 1

Related Questions