I am displaying documents from my Firebase Firestore database into a UITableView. I have created an array called parties that stores my custom data model Party. The data is displaying properly, however, whenever I select a cell, the app crashes and returns the error, "Invalid document reference. Document references must have an even number of segments, but hwh3cztnfcd5aC5ZRgyPNpFUsS33 has 1."
I tried deleting the didSelectRowAt method but the error will still appear.
This is the function I have created that loads the data from Firebase Firestore.
func loadAllParties() {
// Remove all data from the array parties.
parties.removeAll()
if Auth.auth().currentUser != nil {
if let user = Auth.auth().currentUser {
// The user's ID, unique to the Firebase project.
let uid = user.uid
let db = Firestore.firestore()
db.collection(uid).order(by: "timeStamp", descending: false).getDocuments() { (snapshot, error) in
if error != nil {
print("Unable to get documents: \(error)")
} else {
for document in (snapshot!.documents) {
let title = document.data()["title"] as? String ?? "New Party"
let location = document.data()["date"] as? String ?? "No Location"
let date = document.data()["date"] as? String ?? "No Date"
let startTime = document.data()["startTime"] as? String ?? "No Start Time"
let endTime = document.data()["endTime"] as? String ?? "No End Time"
let notes = document.data()["notes"] as? String ?? "No Notes"
self.parties.append(Party(title: title, location: location, date: date, startTime: startTime, endTime: endTime, notes: notes))
self.displayOnboardingIfNeccessary()
}
}
}
}
} else {
print("No user is currently signed in.")
}
}
This is the code for didSelectRowAt.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let party = yourPartiesTableView.indexPathForSelectedRow
let cell = tableView.cellForRow(at: party!) as! YourPartiesTableViewCell
selectedParty = cell.titleLabel.text
performSegue(withIdentifier: "showPartyViewController", sender: self)
}
My expectations were that when you tap the cell, it would perform a segue to the next view controller and let that view controller know what data to get from Firebase on that page.