这是我的问题,我可以在控制台打印双精度值(又名距离),但我不能采取双精度,并在表视图中添加距离为例。
if previousLocation == nil {
previousLocation = locations.first
} else {
guard let latest = locations.first else { return }
let distanceInMeters = previousLocation?.distance(from: latest) ?? 0
print("Distance in meters: (distanceInMeters)")
guard var unwrappedPaceNumber = paceNumber.first else { return }
let total = unwrappedPaceNumber += "(distanceInMeters)"
paceNumber[0] = "(total)"
tableView.reloadData()
previousLocation = latest
}
我最后就这样结束了如果这对你有帮助
if previousLocation == nil {
previousLocation = locations.first
} else {
guard let latest = locations.first else { return }
let distanceInMeters = previousLocation?.distance(from: latest) ?? 0
var distanceRounded = distanceInMeters.rounded()
print("Distance in meters: (distanceRounded)")
let unwrappedPaceNumber = paceNumber[0]
distanceRounded += Double(unwrappedPaceNumber)!
paceNumber[0] = "(distanceRounded)"
print(paceNumber[0])
tableView.reloadData()
previousLocation = latest
}