SWIFT 5.9+ · 15 QUESTIONS · ABOUT 10 MINUTES

Something, or nothing at all?

Swift makes you say when a value might be missing, and copies structs where other languages share objects. Fifteen snippets on optionals, value types, closures and protocols, each explained. No sign-up, nothing saved.

Start the Swift test
let n = Int("4x")print(n ?? 0, n == nil)
output0 true
QUESTION 1 / 15 · OPTIONALSEasy

What does this print?

let n = Int("4x")print(n ?? 0)

What this Swift test measures, in short

This test checks whether you can predict what real Swift does: how optionals unwrap, when a struct is copied versus a class shared, how closures capture values, what protocol extensions dispatch to, and how enums, switch and try fit together.

Snippets assume Swift 5.9 or later at top level. The questions are our own and not standardised against a population, so treat the result as a knowledge check, not a certification.

By What's Your IQ · Reviewed 4 Oct 2026
Format
15 predict-the-output questions, 4 options each
Topics
Optionals, structs and classes, closures, protocols, enums and errors
Version
Swift 5.9+
Language
Started by Chris Lattner at Apple; announced 2014
SIX WAYS TO UNWRAP

What happens when the box is empty?

An Int? is a box that holds an Int or nothing. Pick what the user typed, then compare how each technique handles it.

let n = Int(input) // input =
n is Optional(42)
if letSafe
if let n { print(n + 1)} else { print("none")}
→ 43The everyday choice. Inside the braces n is a plain Int. Since Swift 5.7 you can write if let n without repeating = n.
guard letSafe
guard let n else { return "none"}return "\(n + 1)"
→ "43"Exits early when nil and keeps n unwrapped for the rest of the function. The usual way to validate input.
?? defaultSafe
print((n ?? 0) + 1)
→ 43Always produces a value. Good when a fallback really makes sense, risky when 0 hides a bug.
Optional chainingStill optional
print(n?.description)
→ Optional("42")Never crashes, but the result is still optional, so the problem moves further down your code.
mapStill optional
print(n.map { $0 * 2 })
→ Optional(84)Transforms the value if there is one, keeps nil if not. Useful in chains.
Force unwrap !Got lucky
print(n! + 1)
→ 43Fine only when nil is truly impossible. When it isn't, the app crashes.
WRITING IT THE SWIFT WAY

Objective-C habits, Swift solutions

OLD HABIT
let url = URL(string: text)!let data = try! Data(contentsOf: url)show(data)
SWIFTY
guard let url = URL(string: text) else { return showError("Bad link")}do { show(try Data(contentsOf: url))} catch { showError(error.localizedDescription)}

Every ! and try! is a possible crash. guard and do/catch handle the failure cases explicitly and keep the happy path flat.

"Protocol-oriented"Apple's own description of SwiftThe 2015 WWDC talk argued for protocols and value types over class hierarchies. Questions 10 to 12 test what that means in practice.2
2010 → 2014A secret successor. Chris Lattner, creator of LLVM, began Swift in 2010; Apple announced it at WWDC 2014 to replace Objective-C.1
2015Open source. Swift was released under the Apache 2.0 licence, with Linux support from the start.1
2019 · 5.0ABI stability. The Swift runtime shipped inside Apple's operating systems, so apps no longer had to bundle it.3
2021 · 5.5async/await and actors. Structured concurrency was built into the language, with compiler checks against data races.3
  1. Swift.org. About Swift.
  2. Abrahams, D. (2015). Protocol-oriented programming in Swift. Apple WWDC, session 408.
  3. Swift.org. Swift 5.0 and 5.5 release announcements. Swift Blog.

Where to go next

You know Swift. How do you reason?

Our full IQ test measures the logic and working memory behind good code: 60 questions across four domains, about 30 minutes.

Take the full IQ test