0

这是我的问题,我可以在控制台中打印双精度值(也就是距离),但我不能使用双精度值并在表格视图中添加距离,例如。

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
        }
4

1 回答 1

0

我终于像那样结束了如果这可以帮助

 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
        }
于 2021-01-27T08:30:51.467 回答