Swift Language Converting Swift string to a number type


Int("123") // Returns 123 of Int type
Int("abcd") // Returns nil
Int("10") // Returns 10 of Int type
Int("10", radix: 2) // Returns 2 of Int type
Double("1.5") // Returns 1.5 of Double type
Double("abcd") // Returns nil

Note that doing this returns an Optional value, which should be unwrapped accordingly before being used.