· 3 min read

Master Swift Optionals, Structs and Actors: 48 Flashcards for iOS Developers

Learn Swift with 48 flashcards: optionals and guard let, struct vs class, protocol extensions, weak vs unowned, async/await and actors, plus 4 cards to fix.

Flat vector illustration of a swift bird flying past a translucent shield and floating flashcards

Studying. But it's also a video game. 🎮

Flashcards, quizzes and games that make you actually remember.

Start playing — it's free

Posted by

Swift enforces what Objective-C left to convention: nothing is nil unless you say so, structs are copied, and a switch over an enum must cover every case. Deck UL5709 — Swift Essentials turns that contract into 48 flashcards, almost all carrying compilable code on the back. Here is the map, plus the four cards to repair before your first review.

Study this deck: Swift Essentials

1 / 10
Question

Swift

Knew itLearning

Tap the card for the answer · swipe right if you knew it, left if not

The 48 cards, block by block

  • Optionals — the spine of the deck (7 cards): String? declarations, optional binding with if let, guard let, optional chaining (person?.address?.city), nil coalescing ??, forced unwrapping !, implicitly unwrapped optionals for IBOutlets
  • Types and semantics: Int8/Int16/Int32/Int64/UInt, Float, Double, Bool, String, Character, Array<T>, Dictionary<K,V>, Set<T>, struct vs class, value copies vs shared references, mutating, is / as? / as!, Any vs AnyObject
  • Properties and init: computed properties (get/set), willSet/didSet observers, lazy var, static vs class members, custom init, failable init?, override/super, final
  • Protocols, enums, generics: protocol requirements, protocol extensions as default implementations, enums with associated values, exhaustive switch, if case .success(let msg), generic Stack<Element>, type constraints (<T: Equatable>), extension Int
  • Memory and concurrency: retain cycles, weak vs unowned, capture lists [weak self], @escaping, defer, do/try/catch, try? and try!, map/filter/reduce/compactMap/flatMap, async/await, Task, actor

Ten cards to quiz yourself on right now

FrontBack (condensed)
Nil coalescing operatorlet name = optionalName ?? "default" — supplies a fallback when the optional is nil
Optional chainingperson?.address?.city — calls through only if non-nil, returns an optional, stops at the first nil
struct vs classStruct: value type, copied, no inheritance, no deinit. Class: reference type, shared, inheritance, deinit
Guard statementguard let name = optionalName else { return } — early exit, unwrapped value stays in scope afterwards
Protocol extensionextension Drawable { func describe() { … } } — default implementation every conforming type inherits
Weak vs unownedweak: optional, becomes nil on deallocation. unowned: non-optional, assumes the object outlives you
Capture listsomeMethod { [weak self] in self?.doSomething() } — breaks the closure's retain cycle
CompactMap["1","2","three","4"].compactMap { Int($0) } → [1, 2, 4] — maps and drops nils
Failable initializerinit?(name: String) { if name.isEmpty { return nil } … } — returns an optional instance
Actoractor BankAccount { … } — reference type with serialized access; call it with await

Four cards to fix before you start

  1. Card 19 redefines Result. It declares its own enum Result { case success(String); case failure(Error) }, but Swift has shipped Result<Success, Failure> since 5.0 — rename the deck's to MyResult.
  2. Three backs are truncated mid-word: error handling stops at print("Other error: \(er, the escaping-closure card at Need [weak self] to avo, the struct-methods card at coun. Finish them from memory, it is a free extra rep.
  3. Hello World contradicts itself: it says "no main function needed", then shows one. For an app target the modern answer is @main on a type with static func main().
  4. flatMap needs a footnote: flattening nested arrays is right, but flatMap over a sequence of optionals was deprecated in Swift 4.1 in favour of compactMap.

Two drills that fit this deck

The unwrap ladder. Take one optional and write all five handling paths in a row: if let, guard let, ??, ?., !. The deck teaches them as five separate cards; interviews ask which one you'd pick and why.

The struct/class flip. Card 16 gives the three reasons to reach for a class — inheritance, reference semantics, a deinitializer. Go through the type cards and name which of the three applies. Everything else stays a struct.

Deck UL5709 — Swift Essentials is in the Flip It library at flip-it.app. Coming from another modern language? Compare notes with the Go Essentials study guide or the Rust ownership and borrowing deck.

Ready to learn faster? 🚀

Join FLIP IT for free and turn studying into a game.

Create my free account