未找到更新错误 Parse Swift 的对象 [英] Object not found for update error Parse Swift

查看:41
本文介绍了未找到更新错误 Parse Swift 的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 7.2 上使用 parse,但无法快速更新对象.我想在解析类列批准"中更新我的布尔值,我的类名是请求",我有FromUserName"列是字符串类型,ToUsername"列也是字符串

I'm using parse on Xcode 7.2 and I'm having trouble updating the object with swift. I want to update my boolean value in parse class column "Approve" and my class name is "Request" and I have "FromUserName" column which is type String and "ToUsername" column which is String as well

这是我的快速代码

 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)

我现在不知道该怎么办.

I don't know what to do now.

感谢任何帮助.谢谢

这是我保存的方法

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

推荐答案

尝试将您的保存代码更改为:

Try changing your save code to this:

    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 后端的配置方式来使用它们:

will set it so anyone can edit to the object though. That may not be exactly what you want. There are other methods too that can allow someone to write over an object. You may be able to use them depending on your needs and how your Parse backend is configured:

    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 方法后保存的对象.如果要在解析中编辑当前对象,则必须手动更改数据库本身的读写权限.

Also note that this will not work for current objects in parse. Only for objects saved after adding the setWriteAccess method. If you want to edit current objects in parse, you have to change the read and write permissions form the database itself, manually.

这篇关于未找到更新错误 Parse Swift 的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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