I'm a newbie in Swift -please have mercy- with my code, I can not remove .childRemoved from external Firebase server due to expected Int instead of Stringand can not figure out how to remove from my tableview a message that I'm erasing from the external Firebase
import UIKit
import Firebase
class FCViewController: UIViewController, UINavigationControllerDelegate {
var ref: FIRDatabaseReference!
var messages: [FIRDataSnapshot]! = []
func configureDatabase() {
ref = FIRDatabase.database().reference()
ref.child("messages").observe(.childRemoved, with: { (snapshot) in
// MY PROBLEM 1: can not remove this chat with such identifier from the external Firebase server because an Int is expected instead of an String
self.messages.remove(at: snapshot.key)
// MY PROBLEM 2: when solving PROBLEM 1, table does not reload from Firebase like this, check on the comments the link for the answer to this:
// reload table to featch data from Firebase
self.messagesTable.reloadData()
}, withCancel: nil)
}
}
snapshot.key
prints: -KflJWAyY3KSyyN8RA5U
self.messages prints:
[Snap (-KflJVkAYLaoEiFPD86N) {
name = "user 1";
text = fadsfd;
timestamp = "2017-03-21 14:42:45 +0000";
},
Snap (-KflJWAyY3KSyyN8RA5U) {
name = "user 1";
text = adsfasdf;
timestamp = "2017-03-21 14:42:45 +0000";
}]
Thank you!