我在尝试更新PFObject时遇到此错误' [错误]:没有与查询匹配的结果。 (代码:101,版本:1.12.0)'这是我的代码:
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")
答案 0 :(得分:0)
以下是如何使用PFUser.query()
在解析中查询用户类的示例,请注意,我的示例使用findObjectsInBackgroundWithBlock()
,而不是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)
}
})
}
并且为了更新给定用户的值,您将...
func updateObjectInParse(){
currentUser?.setObject(campaignMottoText.text, forKey: "columnNameInParse")
currentUser?.saveInBackground()
}
其中"columnNameInParse"
是要在parse中更新的对象的列的名称。这是区分大小写的。而currentUser是PFUser.currentUser