快速/解析getObjectInBackgroundWithId查询无法正常工作

索蒂里斯·卡尼拉斯(Sotiris Kaniras)

我正在尝试使用的getObjectInBackgroundWithId方法,PFObject它会引发此错误:

"Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type (string, block: (PFObject!,NSError?) -> Void"

我写了下面的代码:

var result = PFQuery(className: "posts")
    result.getObjectInBackgroundWithId("kk", block: {
        (object: PFObject, error: NSError?) -> Void in
        object["pLikes"] = object["pLikes"] + 1

        object.save()
    })

有什么帮助吗?

阿什什·卡卡德

您必须使用getObjectInBackgroundWithId

let query = PFQuery(className: "posts")
query.getObjectInBackgroundWithId("kk") { (objects, error) -> Void in

}

或者

let query = PFQuery(className: "posts")
query.getObjectInBackgroundWithId("kk") { (objects:PFObject?, error:NSError?) -> Void in

}

改变对象

let query = PFQuery(className: "posts")
query.getObjectInBackgroundWithId("kk") { (objects, error) -> Void in
    let testObj = objects?.first as! PFObject
    testObj.setObject(26, forKey: "pLikes")
    testObj.saveInBackgroundWithBlock { (succeeded, error) -> Void in
        if succeeded {
            println("Object Uploaded")
        } else {
            println("Error: \(error) \(error!.userInfo!)")
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章