enter image description here enter image description here这是我的Xcode项目。我已经将它连接到firebase,但我一直收到错误:
2017-11-28 12:37:38.478475-0500 RatFinder_ios[1099:21397] ***
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<FIRDatabaseReference 0x600000853170> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key City.'
我很困惑,因为我遵循了所有符合编码规则,并确保传递给函数的信息是:
func writeToFirebase()
{
let refRats = Database.database().reference()
let key = refRats.childByAutoId().key
guard let dateText = dateTextField.text, let boroughText = boroughTextField.text, let locationTypeText = locationTypeTextField.text, let addressText = addressTextField.text, let cityText = cityTextField.text, let zipText = zipTextField.text, let latitudeText = latitudeTextField.text, let longitudeText = longitudeTextField.text, let createdDateIntText = createdDateInt() else { return }
//creating rat with the given values
let rat: [String: Any] = Sighting.init(createdDate: dateText, createdDateInt: createdDateIntText, incidentAddress: addressText, locationType: locationTypeText, incidentZip: zipText, city: cityText, borough: boroughText, latitude: latitudeText, longitude: longitudeText).toDictionary()
refRats.child(key).setValuesForKeys(rat)
}