我正在尝试使用的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] 删除。
我来说两句