Category: Swift
How I Fixed a Retain Cycle Between a Swift View Controller and an Async Callback
By Seren |
19 Oct, 2026
Leave a comment
I found this retain cycle after a screen that looked completely gone kept receiving updates from a slow network callback. The view controller disappeared, but its memory stayed around until the request finished. Instruments showed the leak; the difficult part was understanding why a small closure had kept an entire screen alive. The Screen That […]
Swift Retain Cycles: Three Solutions and When to Use Each
By Seren |
29 Sep, 2026
2 Comments
I stopped adding [weak self] to every Swift closure after debugging a download screen that stayed alive after it was closed. The leak was real, but the useful lesson was not that closures are dangerous. The problem was a specific ownership loop: the screen model owned a progress source, the source stored a closure, and […]
static vs class in Swift: When Type Methods Can (and Can’t) Be Overridden
By Seren |
27 Sep, 2026
Leave a comment
I used to choose between Swift’s static and class keywords by habit. If a function belonged to a type instead of an instance, I usually wrote static and moved on. That worked until I built a notification layer where each delivery channel needed its own type-level behavior. Email and SMS builders shared validation and construction […]
Swift Struct mutating Keyword Explained: When Value Types Need to Modify Themselves
By Seren |
26 Sep, 2026
Leave a comment
I stopped thinking of Swift’s mutating keyword as a compiler formality after building a checkout model with several valid stages. A cart could be edited while shopping, locked before payment, marked as paid, or reset. Letting outside code assign those properties directly made invalid combinations too easy to create. I moved the transitions into a […]
Swift Concurrency: Async/Await in Real Projects
By Seren |
25 Sep, 2026
Leave a comment
My first useful Swift concurrency refactor was not a large rewrite. It was a dashboard screen that loaded a profile, notifications, and small labels for each notification. The callback version worked, but it mixed request coordination, error handling, shared cache updates, and UI delivery in one difficult-to-review function. I rebuilt that flow as a small […]
Result Enum: Handling API Success and Failure Elegantly
By Seren |
24 Sep, 2026
Leave a comment
I became more careful with API completion handlers after debugging a catalog screen that could finish with both values set to nil. The request technically completed, but the caller could not tell whether the server had returned an empty response, decoding had failed, or someone had simply forgotten to pass an error. I replaced that […]
Swift Generics Advanced + Protocol Associated Types: From “Can Use” to “Can Design”
By Seren |
23 Sep, 2026
Leave a comment
I did not start using advanced Swift generics because I wanted a more abstract architecture. I used them because a synchronization feature allowed the wrong local cache and remote source to be connected. Both objects had methods named load and save, so the mistake looked reasonable until data reached the wrong layer. The fix was […]
Swift Higher-Order Functions: map, filter, reduce, flatMap in Real Projects
By Seren |
22 Sep, 2026
Leave a comment
I used to judge Swift collection code by line count. If a chain of map, filter, and reduce replaced a loop, I assumed the result was automatically better. A reporting feature changed that habit. The first functional version was short, but it performed unnecessary work and hid an important rule about refunded orders. The useful […]
Swift Closures Explained: @escaping, Non-Escaping, and Trailing Closures with Code
By Seren |
21 Sep, 2026
Leave a comment
I understood Swift closure syntax long before I understood closure lifetime. I could write map, completion handlers, and trailing closures without thinking about them. The gap only became obvious when a profile screen refused to deallocate after it was dismissed. The screen asked an avatar pipeline to load an image. The pipeline stored a completion […]
Swift Value Type Copy-on-Write Mechanism
By Seren |
19 Sep, 2026
Leave a comment
I did not learn copy-on-write from an interview question. I learned it while profiling a document editor that kept a published version and an editable draft in memory at the same time. Each document contained thousands of text lines. I expected creating the draft to duplicate all of that storage immediately, but the assignment was […]
