我在下面的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)

我没有编译错误,但是在运行应用程序时,出现以下运行时错误:

ios - 无法从plist读取CLLocationDegrees-LMLPHP

重要的是要说我正在从plist 加载数据。有人可以告诉我我在做什么错吗?

编辑:

现在我有这些错误:
ios - 无法从plist读取CLLocationDegrees-LMLPHP

最佳答案

错误非常明显:您正在将字符串类型的值转换为NSNumber

尝试以下方法:

let latitudeStr = dictionary["Latitude"] as! String
self.latitude = CLLocationDegrees(latitudeStr)!

并且您也应该对"Longitude"属性执行相同的操作;)

您可能还会遇到本地号码问题。尝试这个:
let numberFormatter = NumberFormatter()
numberFormatter.decimalSeparator = ","
numberFormatter.thousandSeparator = "."
...
self.latitude = numberFormatter.number(from: latitudeStr)!.doubleValue

09-07 14:20