[英]swift/parse getObjectInBackgroundWithId query not working
我正在嘗試使用PFObject
的getObjectInBackgroundWithId
方法,並且拋出此錯誤:
"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!)")
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.