Swift
String Concatenation
Programming
iOS Development
Swift Language

How do I concatenate strings in Swift?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Swift gives you several straightforward ways to concatenate strings. The most common are the + operator, +=, append, and string interpolation. The best choice depends on whether you are joining a few known strings, building text incrementally, or embedding values into a sentence.

Using the + operator

The simplest approach is +.

swift
1let firstName = "John"
2let lastName = "Doe"
3let fullName = firstName + " " + lastName
4print(fullName)

This is clear and fine for small fixed combinations.

Using string interpolation

If you are building human-readable text, interpolation is often more readable.

swift
1let firstName = "John"
2let lastName = "Doe"
3let fullName = "\(firstName) \(lastName)"
4print(fullName)

Interpolation also works well with numbers and expressions.

swift
let count = 3
let message = "You have \(count * 5) items in your cart."
print(message)

For user-facing strings, interpolation is often the cleanest style.

Using +=

If you are mutating an existing string, += is convenient.

swift
var greeting = "Hello"
greeting += ", world"
print(greeting)

This is readable for simple incremental construction.

Using append

Swift strings also support append.

This is particularly nice when a string is being built step by step inside conditional logic and you want the mutation to read explicitly rather than through repeated binary concatenation expressions.

swift
var text = "Hello"
text.append(", Swift")
print(text)

This is especially useful when the code already works with a mutable String and wants to add one more piece without introducing extra intermediate expressions.

Joining many strings

If you need to combine many pieces, especially from an array, use joined(separator:).

swift
let parts = ["red", "green", "blue"]
let result = parts.joined(separator: ", ")
print(result)

This is better than chaining many + operations when the values already live in a collection.

Which style to use

A practical rule is:

Swift supports several valid styles, so the real question is usually not “which one exists,” but “which one makes the intent of this particular string-building code easiest to read.”

  • use + for a few simple string pieces
  • use interpolation for readable sentences with values
  • use += or append when building a mutable string step by step
  • use joined(separator:) for arrays of strings

Swift supports all of them, so choose based on readability rather than treating one as universally correct.

Performance perspective

For ordinary app code, readability matters more than micro-optimizing tiny string joins. If you are building very large strings inside tight loops, prefer patterns that reflect incremental construction clearly and avoid awkward repeated concatenation patterns.

In most Swift app code, the better choice is simply the one that makes the produced string obvious to the next developer reading the function.

In normal UIKit or SwiftUI code, the difference is usually far less important than keeping the result easy to read.

Common Pitfalls

A common mistake is overusing + for long user-facing messages when interpolation would be clearer.

That kind of code still works, but it tends to hide the final shape of the string instead of making it obvious at a glance.

Another mistake is manually joining array elements with loops when joined(separator:) already expresses the intent directly.

A third mistake is forgetting that only mutable strings can use += or append.

Summary

  • Use + for simple direct concatenation.
  • Use interpolation for readable strings with embedded values.
  • Use += or append when building a mutable string incrementally.
  • Use joined(separator:) for arrays of strings.
  • Choose the style that makes the resulting code easiest to read.
  • Prefer interpolation when building natural-language output with embedded values.

Course illustration
Course illustration

All Rights Reserved.