"convert int to string in swift" Code Answer

2

converting int to string:

let x : int = 42
var mystring = string(x)

and the other way around - converting string to int:

let mystring : string = "42"
let x: int? = mystring.toint()

if (x != nil) {
    // successfully converted string to int
}

or if you're using swift 2 or 3:

let x: int? = int(mystring)
By Thanh-Nhon Nguyen on May 6 2022

Answers related to “convert int to string in swift”

Only authorized users can answer the Search term. Please sign in first, or register a free account.