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.
On this page3 sections
Swift topics, one page each
- Swift optionals interview questionsSwift optionals for interviews: what an optional is, if let and guard let, force unwrapping, optional chaining, Optional.map and switch.
- Swift structs and classes interview questionsSwift structs and classes for interviews: value versus reference types, mutating, ===, inout, convenience initializers and property observers.
- Swift closures interview questionsSwift closures for interviews: closure syntax, trailing closures and $0, capturing values, passing functions, reduce and nested functions.
- Swift protocols interview questionsSwift protocols for interviews: requirements, protocol extensions, extending types, associated types, synthesized Hashable, composition, generics.
- Swift enums interview questionsSwift enums for interviews: enums with methods, associated values, raw values, switch patterns, CaseIterable, indirect enums and Optional.
- Swift error handling interview questionsSwift error handling for interviews: throws and do/catch, try? and try!, custom errors with values, defer, the Result type and typed throws.
- Swift collections interview questionsSwift collections for interviews: Array, Set and Dictionary, safe lookups, filter and map, iterating dictionaries, sets, strings and slices.
- Swift ARC and memory management interview questionsSwift memory management for interviews: how ARC works, ARC versus garbage collection, reference cycles, [weak self], value types and leaks.
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.
What happens when this Swift code is compiled and run?
let x: Int? = 5
print(x)
print(x!)- 1
5, then 5 - 2
Optional(5), then Optional(5) - 3
It does not compile: print needs an unwrapped value
- 4correct
Optional(5), then 5
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.
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.