gpt4 book ai didi

xcode - 未找到更新错误的对象 Parse Swift

转载 作者:行者123 更新时间:2023-11-30 13:48:05 25 4
gpt4 key购买 nike

我在 Xcode 7.2 上使用 parse,但在使用 swift 更新对象时遇到问题。我想更新解析类列“Approve”中的 bool 值,我的类名是“Request”,我有“FromUserName”列,它是字符串类型,“ToUsername”列也是字符串

这是我的 swift 代码

 func block(){
let name = self.userDelName
let query = PFQuery(className: "Request")
//let username = PFUser.currentUser()?.username!
if let username = PFUser.currentUser()?.username! {
query.whereKey("ToUsername", equalTo: username)
}
query.whereKey("FromUsername", equalTo: name)
print(name+" IMHEHEHEHEHERRRR")
query.getFirstObjectInBackgroundWithBlock{(object,error) -> Void in
if error == nil {
print(object)
object!["Approve"] = false
object!.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
if (success) {
print("success")
} else {
print("down")
print(error)
}
}

}
}

}

错误是

[Error]: object not found for update (Code: 101, Version: 1.11.0)

我现在不知道该怎么办。

感谢任何帮助。谢谢您

编辑:这是我保存的方法

requested = PFObject(className: "Request")
requested!["From"] = PFUser.currentUser()
requested!["FromUsername"] = PFUser.currentUser()?.username
requested!["ToUsername"] = user
requested!["To"] = newFriend
requested!["Approve"] = true
requested!.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
if error == nil {
print("success")
}
else{
print(error)
}
}

最佳答案

尝试将保存代码更改为:

    requested = PFObject(className: "Request")
requested!["From"] = PFUser.currentUser()
requested!["FromUsername"] = PFUser.currentUser()?.username
requested!["ToUsername"] = user
requested!["To"] = newFriend
requested!["Approve"] = true
requested.ACL?.setPublicWriteAccess(true)
requested!.saveInBackgroundWithBlock {(success: Bool, error: NSError?) -> Void in
if error == nil {
print("success")
}
else{
print(error)
}
}

行:

 ACL?.setPublicWriteAccess(true)

将设置它,以便任何人都可以编辑该对象。这可能不完全是您想要的。还有其他方法可以允许某人重写对象。您可以根据您的需要以及 Parse 后端的配置方式来使用它们:

    object.ACL?.setWriteAccess(allowed: Bool, forRole: PFRole)
object.ACL?.setWriteAccess(allowed: Bool, forRoleWithName: String)
object.ACL?.setWriteAccess(allowed: Bool, forUser: PFUser)
object.ACL?.setWriteAccess(allowed: Bool, forUserId: String)

另请注意,这对于解析中的当前对象不起作用。仅适用于添加 setWriteAccess 方法后保存的对象。如果要编辑解析中的当前对象,则必须手动更改数据库本身的读写权限。

关于xcode - 未找到更新错误的对象 Parse Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34671553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com