将 Swift 字符串转换为数字类型

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

请注意,执行此操作会返回 Optional 值,该值应在使用前相应地解包