NEW: Master Swift design patterns with my latest book! >>

How to convert an int to a string

Written by Paul Hudson    @twostraws

Swift's string interpolation means you can convert all sorts of data – including integers – to a string in just one line of code:

let str1 = "\(myInt)"

However, the more common way is just to use the string constructor, like this:

let str2 = String(myInt)

Available from iOS 7.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Hacking with watchOS

Transfer your Swift skills to watchOS the easy way, and learn to build real-world apps in the process!

Click here to visit the Hacking with Swift store >>