gpt4 book ai didi

ios - swift/parse getObjectInBackgroundWithId 查询不起作用

转载 作者:行者123 更新时间:2023-11-30 14:11:08 24 4
gpt4 key购买 nike

我尝试使用 PFObjectgetObjectInBackgroundWithId 方法,但它抛出此错误:

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

关于ios - swift/parse getObjectInBackgroundWithId 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31761505/

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