Skip to content
Strings
step 1/5

Reading — step 1 of 5

Learn

~1 min readStrings and Optionals

Swift strings are full Unicode — they handle emoji, combining characters, scripts properly. The trade-off is that .count is O(n) (Swift counts grapheme clusters, not bytes).

let s = "hello, world"
print(s.count)                    // 12
print(s.uppercased())              // HELLO, WORLD
print(s.contains("world"))         // true
print(s.split(separator: ","))     // ["hello", " world"]

String interpolation uses \(expression):

let name = "Alice"
let age = 30
print("\(name) is \(age) years old")

Multi-line strings use triple double-quotes. They preserve indentation relative to the closing """.

Strings are value types — passing a string copies it (with copy-on-write optimization, so it's cheap until you mutate).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…