The Problem: Direct View-to-View Navigation Most apps start with views directly pushing to other views: push(to: ViewB()). This seems simple at first, but quickly becomes a maintenance nightmare. View to View Navigation Cons of Direct Navigation Tight coupling: ViewA must know how to create ViewB instance, including all its dependencies Scattered state: App state is spread across multiple viewModels, making state correctness nearly impossible Single responsibility violation: Each view handles both its own logic AND navigation logic Difficult testing: Views own both state and navigation, making isolated unit tests extremely hard Deeplink hell: No centralized place to handle deeplinks—logic gets duplicated everywhere Hard to understand flows: Navigation paths are scattered across the codebase....
Part 2 - State Driven Navigation: Tutorial
💡 Read Part 1 first to understand the concept. This post shows you exactly how to implement it. What We’re Building A simple 3-screen onboarding flow: Account Loader Screen → Loads the user’s account in a loader screen Welcome Screen → user taps “Get Started” Device Identification Screen → user enters their devices CMMac Let’s build this with state-driven navigation, step by step. 1 - States States represent every screen your user can be on:...
What does actor reentrancy mean?
If you captured any state before doing some async work in your actor, then by the time your task is resumed, your captured state may be stale. This is what actor reentrancy is about. Because of this, you should avoid capturing things that are subject to change before your task is suspended. Instead, only retrieve values after your task is resumed. The term “reentrant” literally means “able to be entered again....
Systems Design - Pagination
Cursor-Based Pagination: Handling Deletions, Collisions & Secure Cursors Pagination requires subtle implementation for a smooth infinite scroll. In this post I’ll share what I learned while reading on cursor‑based pagination for a real‑time feed – how it differs from the classic offset/limit approach, how it deals with deletions and timestamp collisions, what goes into a cursor (spoiler: it’s not a random token), why you should (or shouldn’t) protect cursors from tampering, what to cache and how to manage stale data....
High Level Anatomy of a Camera Capturing Session
I used the following tutorial series from Apple on ‘Capturing and Displaying Photos’. They’re great. Just that it took me a bit to be able to piece together how components from AVFoundation work together. Working with AVFoundation isn’t really the kind where you read documentation and then can piece things together. It’s complicated. You might understand an individual step, but won’t understand when it should be done. There’s just too many components and while it’s not low-level, it’s certainly a different kind of iOS....
What Is a Suspension Point In Swift?
A suspension point doesn’t mean the current thread is blocked. Nor it means the current actor is blocked. All it means is that the current task / function is blocked / suspended / waiting for an asynchronous task to finish. @MainActor func foo() async { doA() let b = await doB() doC() } When you get to doB(), then the MainActor / Main Thread are not suspended. Other tasks can be enqueued and executed on the main thread....
Live Activities Part 1 - Problem Statement
I recently went on a quest for Live Activities. There’s a ton of gotchas or subtle notes that aren’t clearly mentioned. Think of the series as an unofficial rfc. Intro Example app - wwdc code - docs confusion points I saw Apple’s videos and docs on ActivityKit. They do a decent job of showing you 80% of the API and how Live Activity works. The remaining 20% is an enigma though....
Live Activities Part 2 - The missing doc
How do I begin development for Live Activities? Follow Apple’s docs: Add a new† (widget) target to your app. Make sure you select ‘Live Activities’. Add the necessary plist items. Add push notification capability. Only needed if you want to start / update from server. If everything is done from within the app then you don’t need this. Example ‘Clock’ App on iPhone adds timers to your phone without any server interaction....
Live Activities Part 3 - Development
Development How can I share classes between widget and app? Models must be shared across targets. App needs the model to manage its lifecycle (start, update, end, handling dismissed / stale activities). Widget needs the model to be able to present it. Each View should only get added to targets that needs them. Your widget must create views based on the models for all Live Activity presentations. Your app may need views if it has an in-app view related to the live activity....
Live Activities Part 4 - Debugging
Debugging Notification delivery issues Can you send Live Activity notifications to simulator? Yes. The token created by the simulator works. Just don’t use the simulator for testing application lifecycle behavior or background tasks as a may not properly simulate OS restrictions. Can you drag and drop payloads into the simulator? That didn’t work for me. Timing of ‘Token Registration’ vs ‘Payload Sending’ Make sure the tokens are stored in your servers before sending the payload....