I hope you could help me: I try to fetch userdata from a firebase database into a user class and call "setValuesForKeys". I do understand that my class properties have to be exactly the same as in the firebase dictionary, but I've got the error "this class is not key value coding-compliant for the key city."
func fetchUsers(){
Database.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
if let usersDictionary = snapshot.value as? [String: String] {
let users = Userdata()
users.setValuesForKeys(usersDictionary)
}
}, withCancel: nil)
}
And my user class is
class Userdata: NSObject {
var email: String?
var password: String?
var firstname: String?
var lastname: String?
var street: String?
var streetno: String?
var zipcode: String?
var city: String?
var phone: String? }
The snapshot from firebase looks like
Snap (ndLBXXX75Oe9Y1PXrqfISL8A4v82) {
city = Washington;
email = "1@a.com";
firstname = Andre;
lastname = Doe;
password = xxxxxx;
phone = "";
street = "Mainstreet";
streetno = 1;
zipcode = 11111;
}
And the dictionary from the database looks like
["city": Washington, "firstname": Andre, "lastname": Doe, "email": 1@a.com, "password": xxxxxx, "streetno": 1, "phone": , "street": Mainstreet, "zipcode": 11111]
I have a solution so far by using:
users.city = dictionary["city"]
My question / problem: I do want to understand the problem behind the error message "this class is not key value coding-compliant for the key city." because the key at the class and in the firebase snapshot looks like the same.