Convert Int to String in Swift
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The normal way to convert an Int to String in Swift is String(number). It is explicit, readable, and works well for everyday cases such as labels, logs, and URLs.
There are other ways to get string output, but they solve slightly different problems. The best choice depends on whether you want a plain conversion, string interpolation, or formatted output.
The Direct Conversion
This is the standard answer:
text is now a real String, so you can pass it to APIs that specifically expect a string value.
This is the best default when you are converting an Int as data rather than building a sentence around it.
String Interpolation Is Not Quite the Same
If you are only embedding the value inside a larger string, interpolation is often cleaner:
You do not need to call String(count) first unless another API specifically wants the converted string separately.
So a useful rule is:
- use
String(number)when you need a string value - use interpolation when you are already building a larger string
description Also Produces a String
Integers also expose description:
This works because Int conforms to string-conversion protocols, but in most ordinary Swift code, String(number) is clearer to readers who are scanning for an explicit type conversion.
Formatted Output Is a Different Problem
Sometimes you do not just want "123". You want padding, grouping, or localization. For example:
That is not better for plain conversion, but it is useful when formatting matters.
For user-facing text, NumberFormatter is often the better tool because it handles locale-aware formatting:
This is the right direction when the output should respect local conventions such as grouping separators.
Common Real Uses
Converting an Int to String shows up in a few common places:
- updating labels in UIKit or SwiftUI
- building file names or URL components
- logging numeric values
- serializing values into plain-text formats
Example:
That is a genuine conversion case. If you were only printing it, interpolation would probably be simpler.
Avoid Premature Formatting Tricks
Some developers reach for String(format:) even when they only need a direct conversion:
That works, but it is more verbose than necessary and introduces formatting syntax that is easy to misuse. Prefer the simple initializer unless you actually need formatting behavior.
Common Pitfalls
The most common mistake is converting too early. If you only need the number inside a sentence, interpolation is often cleaner than storing an extra string variable.
Another mistake is using String(format:) for ordinary conversions. It is fine for padded or formatted output, but overkill for basic cases.
People also forget about localization. A plain integer-to-string conversion is not the same as user-friendly number formatting in every locale.
Finally, keep the distinction between data and presentation clear. String(number) converts data. NumberFormatter controls presentation.
Summary
- Use
String(number)for the normalInttoStringconversion. - Use interpolation when the integer is part of a larger string.
- '
descriptionalso works, butString(number)is usually clearer.' - Use
String(format:)only when you need formatting such as zero-padding. - Use
NumberFormatterfor user-facing localized number formatting.

