[错误]:没有与查询匹配的结果.(代码:101,版本:1.12.0)在 Parse 中使用 Swift [英] [Error]: No results matched the query. (Code: 101, Version: 1.12.0) in Parse using Swift

查看:54
本文介绍了[错误]:没有与查询匹配的结果.(代码:101,版本:1.12.0)在 Parse 中使用 Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试更新 PFObject 时不断收到此错误[错误]:没有与查询匹配的结果.(代码:101,版本:1.12.0)'这是我的代码:

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()


        }        }

我该怎么办?

这是我的新代码:

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

推荐答案

这里是如何使用 PFUser.query() 在解析中查询用户类的示例,注意我的示例使用 findObjectsInBackgroundWithBlock(),而不是 getObjectsInBackgroundWithId()

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()
}

其中 "columnNameInParse" 是要在解析中更新的对象的列的名称.这是区分大小写的.而 currentUser 是 PFUser.currentUser

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

这篇关于[错误]:没有与查询匹配的结果.(代码:101,版本:1.12.0)在 Parse 中使用 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆