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.

Help support Hacking with Swift

This site is funded by Hacking with Swift supporters who buy my e-books. If you can, please support my work – it comes packed with bonus material!

Click here to visit the Hacking with Swift store >>