iOSアプリケーションを構築していて、UITableViewから行を削除しようとしています。私はまた、アプリのモバイルバックエンドとしてParseを使用しています。ここでdeleteメソッドのコードは次のとおりです。iOS Swift 3 Parseを使用してTableViewから行を削除する
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
let query = PFQuery(className: "Receipts")
let currReceipt = receipts[indexPath.row]
query.whereKey("objectId", equalTo: currReceipt.objectId!)
query.findObjectsInBackground(block: { (objects, error) in
if error != nil {
self.createAlert(title: "Oops! Something went wrong number 1!", message: "We could not delete the receipt")
print("THERE WAS AN ERROR DELETING THE OBJECT")
}else{
for object in objects!{
self.receipts.remove(at: indexPath.row)
object.deleteInBackground()
self.table.reloadData()
}
}
})
}
}
だけ明確にするために、そこだけ与えられた「OBJECTID」を使用して、データベース内の1枚の領収書となりますので、query.findObjectsInBackgroundは、単一のオブジェクトを返す必要があります。
シミュレータで行を削除しようとすると、オブジェクトがデータベースに存在することがわかりましたが、「オブジェクトが見つかりません」というエラーが表示されます。私は間違って何をしていますか?
更新 長年探していた私の解決策が見つかりました。関心のある人は、読み取りと書き込みのアクセス許可のデフォルトのACL値と関係があります。答えへのリンクは次のとおりです:Parse weird bug in Swift that causes ACL write permissions to change to an objectId
"!"私は、 "式[暗黙のうちに 'String'から強制されているという警告を受け取ります。 to Any " –
検索の数日後に私のソリューションが見つかりました。興味があった場合:http://stackoverflow.com/questions/34926827/parse-weird-bug-in-swift-that-causes-acl-write -permissions-to-an-objecへの変更 –