Cast from 'Double' to unrelated type 'String' always fails [duplicate]

天涯浪子 提交于 2020-07-15 09:38:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!