Skip to content
December Code

Swift · 8 topic pages · 48 questions in the bank

Swift for placements: interview questions by topic

Swift is the language of iOS, iPadOS and macOS development, and product companies and agencies building apps for Apple's platforms interview on it directly. Candidates often arrive from Java, Kotlin or JavaScript, and interviewers know it, so the questions concentrate on what Swift does differently: optionals instead of null, structs as the default building block, protocols instead of deep class hierarchies, and memory managed by reference counting rather than a garbage collector.

Expect to explain when a struct beats a class and what happens when one is copied, how to unwrap an optional without crashing, what a closure captures and when it must be marked @escaping, how protocol extensions provide default behaviour, how enums with associated values model state, the difference between try, try? and try!, and how [weak self] breaks a reference cycle. Short snippets that ask what a few lines print are common, because they show quickly whether someone knows the rules.

The pages below take one topic each, with answers whose code was compiled with swiftc 6.4 and run, and one question exactly as the diagnostic asks it. The diagnostic draws from every Swift topic in the bank and names the ones to read first.

New to this? How to prepare for placements — the method — and what the readiness test measures.

On this page3 sections

Swift topics, one page each

One question, exactly as the diagnostic asks it

From the Swift bank — 48 questions across 8 topics. The answer is marked because this one is public; in a sitting you choose first, then see why each option is right or wrong.

Optionals · easySWIFT-004

What happens when this Swift code is compiled and run?

Swift
let x: Int? = 5
print(x)
print(x!)
  1. 1
    5, then 5
  2. 2
    Optional(5), then Optional(5)
  3. 3

    It does not compile: print needs an unwrapped value

  4. 4
    Optional(5), then 5
    correct

x is an Int?, an optional wrapping 5. print accepts Any, so it receives the optional itself and describes it as Optional(5); the compiler warns that the expression is implicitly coerced from Int? to Any, which is a hint that this is rarely intended. x! force-unwraps the value, so the second line prints 5. 5, then 5 assumes print unwraps automatically. Optional(5) twice ignores the !. There is no compile error, only the warning. Use if let, ?? or string interpolation with a default to show optionals.

More on this topic: Swift optionals interview questions

Measure it

Reading the answers tells you what’s true. A diagnostic tells you what you get wrong.

10 Swift questions across its topics, easy to hard, about fifteen minutes. You get a readiness figure with the arithmetic shown, the topics you missed named, and a practice set sized for today. Free: a diagnostic in every subject, a retake a week and 15 problems a day. No card.

By Harshit · updated