#23: Convert Int to String in Swift

To convert an integer to a string, initialize String with the integer value:

let count = 42
let value = String(count)
// "42"

String interpolation is equally common when the number is part of a larger message:

let message = "Downloaded \(count) files"

Use String(format:) only when you need formatted output such as fixed width, padding, or locale-aware numeric formatting.


I'm also on Twitter and GitHub.

Subscribe via RSS.