Apple Geek February 2016

[Error]: No results matched the query. (Code: 101, Version: 1.12.0) in Parse using Swift

I keep getting this error when trying to update a PFObject '[Error]: No results matched the query. (Code: 101, Version: 1.12.0)' here is my code:

let userQuery = PFQuery(className: "User")

    userQuery.getObjectInBackgroundWithId("cE3DE48Fa9") {
        (userQueryObject: PFObject?, error: NSError?) -> Void in
        if error != nil {
            print(error)
        }
        else if let userQueryObject = userQueryObject {

            userQueryObject["House_Motto"] = self.campaignMottoTextBox.text

            userQueryObject.saveInBackground()


        }        }

What do I do?

Here is my new code:

currentUser!.setObject(self.campaignMottoTextBox.text!, forKey: "House_Motto")

Answers


MikeG February 2016

Here is an example of how to use PFUser.query() to query the user class in parse, note my example uses findObjectsInBackgroundWithBlock(), rather than getObjectsInBackgroundWithId()

var userData1 = [String]()
var userData2 = [Double]()
var allUsers = [PFUser]()

func fetchUserData() {
    let userQuery: PFQuery = PFUser.query()!

    userQuery.orderByAscending("username")
    userQuery.whereKey("username", notEqualTo: (currentUser?.username)!)
    userQuery.findObjectsInBackgroundWithBlock({
        (users, error) -> Void in

        var userData = users!

        if error == nil {
            if userData.count >= 1 {
                for i in 0...users!.count-1 {
                    self.userData1.append(userData[i].valueForKey("columnNameInParse1") as! String)
                    self.startTimes.append(userData[i].valueForKey("ColumnNameInParse2") as! Double)
                }
            }

            self.allUsers = users as! [PFUser]
            self.tableView.reloadData()
        } else {
            print(error)
        }
    })
}

and in order to update a value for a given user you will do...

   func updateObjectInParse(){
    currentUser?.setObject(campaignMottoText.text, forKey: "columnNameInParse")
    currentUser?.saveInBackground()
}

where "columnNameInParse" is the name of the column for the object of which you want to update in parse. This is case sensitive. And currentUser is the PFUser.currentUser

Post Status

Asked in February 2016
Viewed 2,161 times
Voted 4
Answered 1 times

Search




Leave an answer