0

Here is my problem I can print in console double value (aka the distance) but I can't take a double and add the distance in a table view for exemple.

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
        }
Giovanni Gaffé
  • 36
  • 1
  • 1
  • 10
  • 1
    What do you mean you "can't take a double and add the distance in a table view"? What error did you get? How does the actual result differ from your expectation? – Sweeper Jan 27 '21 at 02:12
  • I'have a fake array with fake data of type String (paceNumber) , When I want to add distance in meters to the first fake dat in the fake array. Compiler say total is of type (). In documentation they say CLlocationDistance is of type Double – Giovanni Gaffé Jan 27 '21 at 03:17

1 Answers1

0

I finally ended up like that If this can help

 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
        }
Giovanni Gaffé
  • 36
  • 1
  • 1
  • 10