Swift Type Conversion
Convert with initialisers: Int("42") returns an optional, String(42) always works. Casting between class types uses as, as? and as!.
Example
let a = Int("42") ?? 0
let b = String(a)
let c = Double(a) / 5
print(a, b, c)Exercise
Number to text.
(42)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.