ios - Swift: Why all my optional variable looks like "Optional(305.502)" -
this question has answer here:
- printing optional variable 9 answers
i've start learning swift. , little confused optional types. have variable var theoptvar: float? can nil make optional ?.
when i'd somewhere @ ui see optional(305.502).
there way have optional var on uilabel without "optional" word?
it displaying “optional” because have changed datatype float optional float.
due whatever value there automatically wrapped optional text.
so if don’t want display optional word extract value out of it.
to add ! mark . this forced unwrapping.
for eg.
var temp : float? temp = 60.5 println(value \(temp!))
Comments
Post a Comment