Part II
Code review
Real-interview code-review snippets in Swift, reviewed from the interviewer's side, with fixes and follow-ups.
Start here
Review this PR
- 01The cell that shows the wrong photo20 minA feed screen with an image cell, a refresh timer and a notification observer — review it.
- 04The converter that shows the wrong answer20 minA currency-converter view model built on async/await — review it, then fix what QA reported.
- 06The SwiftUI list that forgets20 minA SwiftUI transactions screen that reloads, loses its data and stutters — review it.
- 19The login screen that remembers too much20 minA login view model with a "remember me" switch that stores far more than it should, in the wrong places — review it.
- 22Three PRs, rising stakes45 minThree small pull requests in one round — a naming PR with a hidden float bug, a threading PR and an architecture PR — and how to split your time.
- 23The presenter that holds the view20 minAn MVP orders screen — a view controller, a presenter and a view protocol — that leaks, updates the table off the main thread and hides its business rule in didSelect. Review it, fix it without leaving MVP, and write the classic presenter tests.
- 24The tests that pass for the wrong reason20 minA PR that only adds tests — green on the author's Mac, red on CI once a day. Review the tests themselves, fix them minimally, then write the one that was missing.
- 25The PR that is mostly fine15 minA clean, small SwiftUI settings row with one real problem and one judgement call. The test is restraint — find the one thing, say what's fine and why, and approve with comments.
- 27The SwiftUI screen inside a UIKit app20 minA UIKit account screen that hosts a SwiftUI header through UIHostingController — the everyday mid-migration setup — with a crash, a leak, stacked headers and two copies of the same number. Review it and fix it without leaving UIKit.
- 28The checkout that does everything25 minA payment class that prices, stores, logs, calls the network and formats text — review it for SOLID and clean architecture.
- 29The means of payment that never loads20 minA "clean architecture" use case that fetches a member's card — layered on paper, but it hangs on two paths, imports UIKit into the domain and builds its own dependencies. Review it.
What does this print?
- 02What does this print? — queues15 minFour short GCD puzzles on serial vs concurrent and sync vs async, including the two that crash.
- 03What does this print? — closures and values15 minValue vs reference semantics, capture lists, loop captures and defer — five lines of output to predict.
- 11A struct holding a class15 minCopy a struct that holds a class, a class that holds a struct, an array of objects and a copy-on-write type — then count the instances.
- 12Protocol extensions — who gets called?15 minSame method, same object, three different answers — static vs dynamic dispatch through protocol extensions and subclasses.
- 13Initializer order15 minConvenience to designated, two-phase init, the didSet that doesn't fire, an overridden method called from super.init, required and failable inits.
- 14Optional of an optional15 minInt?? from a dictionary of optionals, ?? and if let peeling one layer, map vs flatMap, try? flattening, optional chaining, and an isNil you write yourself.
Review, then extend
- 05A cache for any type25 minA generic cache built on a protocol with an associated type — review it, then make it safe for account data.
- 07The network layer written poorly30 minA completion-handler API client that crashes, hangs and updates UI off main — debug it, then rebuild it with async/await and retries.
- 20The pull-to-refresh merge25 minMerge freshly fetched stories on top of the ones on screen — no duplicates, order kept — review a candidate's version, then make it fast.
- 21The favourite that doesn't stick25 minA list and a detail screen each with a favourite button that drift apart — review it, then fix it with one source of truth and persist it.
Find the bug
- 08The ad that clicks itself20 minA feed with an ad cell whose tap handlers pile up on reused cells — find why ads open when nobody tapped them, and why clicks are counted twice.
- 09Find the leak20 minA profile screen that never deallocates — find all five reasons, explain weak versus unowned, and prove the fix.
- 10The JSON that only decodes on a good day20 minA menu model and a getItemData() decoder that crash the app the first time the backend sends something slightly different — find why.
- 15The token refresh that fires twice20 minA session manager that logs users out at random when two requests need a fresh token at once — find the race, then find it again after it's "fixed" with an actor.
- 16Bad wiring and a race condition20 minA cart screen where Clear adds items, Add adds twice, the count lags by one and big baskets crash — find each cause and say how you'd debug it.
- 17The main thread doing heavy lifting20 minAn articles list that freezes on open and stutters on scroll — find the work that shouldn't be on the main thread, and move it.
- 18Core Data saved from the wrong thread20 minA photo downloader that saves to Core Data from many threads at once — find the crashes, then answer how many managed object contexts it really needs.
- 26The search that shows old results20 minA Combine search pipeline that shows results for what you typed a second ago, stops working after one network error, and never deallocates — find all of it.