查询中的向下转错误

时间:2015-11-17 12:27:54

标签: swift parse-platform

我正在尝试使用查询删除对象。但是我收到了一个沮丧的错误,说[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()

            }
        }
    }

1 个答案:

答案 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!)
  }
}

你还应该检查错误是否 之前重复循环和隐藏指示符的行并按下按钮应该执行一次 重复之后循环。