1

I'm getting the data from the api response I decoded the data properly then I assigned the values to tableview cell

But I'm getting the warning

Cast from 'Double' to unrelated type 'String' always fails

how can I solve this , So that I can assign the double value to the UILabel and get my result

I tried this following code

var rate : Double
cell.priceOfVehicleLabel.text = details.rate as? String
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87

3 Answers3

3

You need

cell.priceOfVehicleLabel.text = "\(details.rate)"
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

You can use String's init(describing:), i.e.

cell.priceOfVehicleLabel.text = String(describing: details.rate)
PGDev
  • 23,751
  • 6
  • 34
  • 88
  • This initialiser is only used for generic types. OP should use NumberFormatter which localizes the string to display it respecting the user's device locale and settings. btw https://stackoverflow.com/a/42043333/2303865 – Leo Dabus Oct 24 '19 at 13:01
0

It's simply cell.priceOfVehicleLabel.text = String(details.rate).

André Slotta
  • 13,774
  • 2
  • 22
  • 34