【发布时间】:2016-02-10 11:43:38
【问题描述】:
下面是我的sn-p
// MARK: - Location Functions
func getCurrentLocation() -> (String!, String!) {
let location = LocationManager.sharedInstance.currentLocation?.coordinate
return (String(location?.latitude), String(location?.longitude))
}
func setCurrentLocation() {
let (latitude, longitude) = getCurrentLocation()
let location = "\(latitude!),\(longitude!)"
print(location)
}
虽然我使用latitude! 和longitude! 解开可选的包装,但它会打印我Optional(37.33233141),Optional(-122.0312186)
我正在打破我的头来删除可选绑定。
【问题讨论】:
-
改成这个
return (String(location?.latitude!), String(location?.longitude!)),你应该添加一些检查以确保它们不是nil,否则你的程序将会崩溃。