[英]how to get firebase value into array and how to delete by uuid?
i am having an issue i can get the value from my realtime database.我有一个问题,我可以从我的实时数据库中获取值。 i'm using this function.
我正在使用这个功能。 bu maybe i'm doing something wrong
但也许我做错了什么
enter c func getPlays(handler: @escaping(_ boat: [GameToSend]) -> ()) {
PLAYS.observeSingleEvent(of: .value) { (playSnap) in
var plays = [GameToSend]()
guard let playsSnapShot = playSnap.children.allObjects as? [DataSnapshot] else { return }
for play in playsSnapShot {
print(play)
let key = play.key
let sport = play.childSnapshot(forPath: "sports").value as? String ?? ""
let winLoss = play.childSnapshot(forPath: "winLoss").value as? String ?? ""
let teams = play.childSnapshot(forPath: "teams").value as? String ?? ""
let picks = play.childSnapshot(forPath: "picks").value as? String ?? ""
let date = play.childSnapshot(forPath: "date").value as? String ?? ""
let playsToSend = GameToSend(key: key, winLoss: winLoss, sport: sport, teams: teams, picks: picks, time: date )
plays.append(playsToSend)
}
handler(plays)
}
}
here i want to delete by uuid instead of key在这里我想通过 uuid 而不是 key 删除
func deleteDataforNotificationVC(key: String) {
PICKS.child(key).removeValue()
}
you delete like this id here udid:你在这里删除这个id:udid:
func authenticateDeleteUserToken(email: String, password: String,id: String) {
Auth.auth().signIn(withEmail: email, password: password) { user, error in
if let error = error {
// An error happened.
self.showAlert(withTitle: appConstants.KAppName.rawValue, message: error.localizedDescription)
} else {
// for User deletion.
user?.user.delete { error in
if let error = error {
// An error happened.
self.showAlert(withTitle: appConstants.KAppName.rawValue, message: error.localizedDescription)
} else { //delete perticular id like child
let ref = Database.database().reference(withPath: "Users")
ref.child(id).removeValue { error, _ in
//success
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.