Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

strings-swift

Strings and interpolation

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Strings and interpolation: the syntax, patterns, and safety habits you need before advancing in Swift.

Teams still ship Strings and interpolation in Swift codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Strings and interpolation in contexts like: iPhone/iPad/Mac apps, server-side Swift (niche), and Apple toolchain projects.

Write Swift in main.swift with print(), click Run on server—the dev runner swiftc compiles and runs the binary (requires Swift toolchain, typically macOS; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Swift String is a value type with full Unicode support. String interpolation embeds values with \(expression)—cleaner than concatenation or format strings.

Interpolation and multiline

let user = "Ada"
print("Hello, \(user)")
print("Next year: \(2026 + 1)")

let poem = """
    Line one
    Line two
    """

Common operations

  • count, isEmpty, hasPrefix, hasSuffix
  • split(separator:), replacingOccurrences(of:with:)
  • Subscript with String.Index—not integer offsets (Unicode-safe)

Important interview questions and answers

  1. Q: Why String.Index instead of Int subscripts?
    A: Swift strings are Unicode-correct—character boundaries are not fixed-width byte offsets.
  2. Q: String vs NSString?
    A: Swift String bridges to Foundation NSString on Apple platforms when importing Objective-C APIs.

Self-check

  1. How do you embed a variable in a string?
  2. What delimiter creates a multiline string?

Tip: Use \(expression) for interpolation—not integer subscripts for character access.

Interview prep

String.Index why?

Unicode-correct strings—character boundaries are not fixed byte offsets.

Interpolation syntax?

\(expression) embeds values in strings.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • String interpolation?
  • Substring cost?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump