Interview guides / ios
Corrupt draft cache: iOS Interview Question
Corrupt draft cache interview question with a clear example answer for iOS engineers. Practice with AceMobileInterview.
This is a common iOS interview topic: Corrupt draft cache.
Below is a concise answer you can adapt in a real interview, then go deeper in the full AceMobileInterview track.
1.Drafts sometimes vanish; truncated JSON can crash the next launch. Fix persistence races and atomicity (≈45–60 min).
## Scenario Draft store writes JSON unsafely and crashes on bad data. ## How to investigate - Force-kill mid-save (or call save repeatedly while editing) - Inspect the drafts file after a crash - Trace `JSONSerialization` / `Data.write` ## Planted bug 1: Non-atomic write **Symptom:** Truncated file after kill **Root cause:** Writing directly to the final path **Fix:** Write to `*.tmp` then `FileManager.replaceItemAt` / atomic options ## Planted bug 2: Crash on decode failure **Symptom:** Launch crash loop **Root cause:** `try!` decode of cache **Fix:** `try?` / `do-catch` → empty draft; optionally quarantine bad file ## Planted bug 3: Unserialized read/write **Symptom:** Intermittent corruption **Root cause:** Saves from textDidChange without coalescing; overlapping writes **Fix:** Serial queue or actor; debounce saves (e.g. 300ms) ## Optimization tips - Mention File Coordination / `NSFileCoordinator` for shared containers - For modern apps, SwiftData/Core Data reduce some of these footguns—but know the file-level answer ## What to say in the interview - How you reproduced partial writes - Why atomic replace matters on mobile (process death is normal)
Keep going with AceMobileInterview
Reading helps. Timed practice locks it in. Jump into the interactive track for algorithms with LeetCode links, studio projects, debugging zips, and mobile system design.