我正在尝试使用查询删除对象。但是我收到了一个沮丧的错误,说[PFObject]的Downcast只是打开选项你是不是意味着使用!?
var query: PFQuery = PFQuery(className: "Posts")
query.whereKey("deleteID", containsString: selectedObjId)
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
for object in (objects as! [PFObject]) {
if error == nil {
//Hide activity indicator and go back to collection view when done deleting
object.delete() // 削除
self.hideActivityIndicator(self.view)
self.quitButtonPressed()
}
}
}
答案 0 :(得分:0)
似乎返回的objects
属于[PFObject]?
类型,因此代替向下展开只需打开对象
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
for object in objects! {
do {
//Hide activity indicator and go back to collection view when done deleting
try object.delete() // 削除
} catch let error as NSError {
print(error)
}
}
self.hideActivityIndicator(self.view)
self.quitButtonPressed()
} else {
print(error!)
}
}
你还应该检查错误是否