I am having some trouble with this following struct
:
struct EmployeeDetails {
let functionary: String
let imageFace: String
let phone: String
let latitude: CLLocationDegrees
let longitude: CLLocationDegrees
init(dictionary: [String: Any]) {
self.functionary = (dictionary["Functionary"] as? String) ?? ""
self.imageFace = (dictionary["ImageFace"] as? String) ?? ""
self.phone = (dictionary["Phone"] as? String) ?? ""
self.latitude = (dictionary["Latitude"] as! CLLocationDegrees)
self.longitude = (dictionary["Longitude"] as! CLLocationDegrees)
I have no compiling errors but, when I run the app, I get this runtime error:
It's important to say that I am loading data from a plist. Anyone could show me what am I doing wrong?
EDIT:
The error is pretty clear: you are casting a string-typed value to a
NSNumber
.Try this instead:
and you should do the same thing to the
"Longitude"
property as well ;)You also may be running into localized numbers issues. Try this: