Python Strings, String Interpolation & Multiline Literals
Swift Strings are fully Unicode-compliant value types. Learn string interpolation (\(expression)), multiline string literals (""" ... """), character counting (.count), string inspection, and string formatting.
"String interpolation in Swift is like a picture frame with cut-out slots: you snap dynamic photo cards (\(user), \(score)) right into the pre-printed border."
Deep Dive: How It Works
String Interpolation: Enclose expressions inside \(expr) to embed dynamic values directly inside string literals.
Multiline String Literals: Triple quotes (""") preserve indentation, line breaks, and quotation marks without backslash escapes.
Grapheme Clusters: Swift strings handle complex Unicode emojis and accents accurately when counting characters (s.count).
Syntax Blueprint
let name = "Alice"
let greeting = "Hello, \(name)!"
let multiline = """
Line 1
Line 2
"""Interpolate values with \() and create multi-line text blocks with triple quotation marks.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Trying to access string characters using integer indexing (e.g. str[0]).Why it happens: Because UTF-8 graphemes vary in byte length, Swift requires String.Index (str[str.startIndex]) to guarantee O(1) correctness.
How to fix: Use string.prefix(n), or iterate characters with for char in str.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Format Dynamic Server Metric
Declare let host = "api.zencompiler.com" and let port = 8080.
Declare let isSecure = true.
Print "Server connected to \(host):\(port) (SSL: \(isSecure))".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.