現在、swiftとFirebaseで本管理アプリを作っています。
データベースに接続し、あたらしいToDoを追加するところまではうまくいったのですが、
削除をするときにref.child(key).remove()という削除の仕方をするようで、keyの値の求め方がわかりません。
色々調べてみるとsnapshotから受け取ようなのですが、実装の仕方がわかりません。
ご教授いただけたらと思います。
よろしくお願いいたします。
データベースの構造は下記です
現在の実装状況は下記です。
実行するとエラーになります。
エラー内容
Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
swift
1// データを削除 2 func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { 3 //デリートボタンを追加 4 if editingStyle == .delete { 5 //選択されたCellのNSIndexPathを渡し、データをFirebase上から削除するためのメソッド 6 self.delete(deleteIndexPath: indexPath) 7 //TableView上から削除 8 tableView.deleteRows(at: [indexPath as IndexPath], with: .fade) 9 } 10 } 11 // 削除メソッド 12 func delete(deleteIndexPath indexPath: IndexPath) { 13 14 Database.database().reference().child("users").child(userID).child(contentsArray[indexPath.row].key).removeValue() 15 contentsArray.remove(at: indexPath.row) 16 17 } 18}
あなたの回答
tips
プレビュー