Swift 3 Convert Double to String

I keep getting this error. β€œThe initializer for the conditional binding must be of an optional type, notβ€œ Double. ”I am trying to display some basic data data, and this is double. Ive tried to get around this the same way I had to do to save the values ​​when converting it.

heres code that gives me an error:

func displayStats() { // display other attributes if they have values if let servingSize = mealstats.serving { servingsLabel.text = servingSize } 
+5
source share
1 answer

foodstats.serving is likely to be of type "Double" and not "Double?"
Since it is not optional, it cannot be deployed. The correct way to use it is

 func displayStats() { // display other attributes if they have values servingsLabel.text = "\(mealstats.serving)" } 
+5
source

Source: https://habr.com/ru/post/1259342/


All Articles