问题
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
回答1:
You need
cell.priceOfVehicleLabel.text = "\(details.rate)"
回答2:
You can use String's
init(describing:)
, i.e.
cell.priceOfVehicleLabel.text = String(describing: details.rate)
回答3:
It's simply cell.priceOfVehicleLabel.text = String(details.rate)
.
来源:https://stackoverflow.com/questions/58539019/cast-from-double-to-unrelated-type-string-always-fails