
我只是想将CLLocationdegrees值保存到Core Data中.但我所做的一切都在起作用.
我开始时:
self.myLocation?.locationCurrentLat = self.fixedLocation?.coordinate.latitude
但是不知道如何让CLLocationdegrees向Double或NSNumber投降(如果这是正确的话),我在Google上搜索的任何东西都无济于事!
关于很多事情,我显然仍然模糊不清.这肯定是其中之一.
我可能做错了什么……或者需要做什么?
提前致谢
CLLocationdegrees是双倍的.你不应该做任何事情.如果确实需要将其强制转换为double,请使用语法
Double(self.fixedLocation?.coordinate.latitude ?? 0)
要转换为NSNumber,您可以使用
NSNumber(value: self.fixedLocation?.coordinate.latitude ?? 0)
编辑:
我编辑了上面的代码,如果self.fixedLocation为nil,则使用“nil coalescing operator”给出值0.如果fixedLocation为nil,则返回包含nil的可选Int会更安全:
let latitude: Double?if let location = self.fixedLocation { latitude = Double(location.coordinate.latitude)} else { latitude = nil} 总结 以上是内存溢出为你收集整理的将CLLocationDegrees更改为Double/NSNumber以保存在Core Data(Swift)中全部内容,希望文章能够帮你解决将CLLocationDegrees更改为Double/NSNumber以保存在Core Data(Swift)中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)