YouMind
Sign in

I cut my iOS edit loop from minutes to about a second

@aswincode
ENGLISHDec 02, 2026
115K
748
49
53
1.7K

TL;DR

The author details a workflow using InjectionLite to enable Swift hot reload, reducing iOS UI verification time from minutes to seconds. This setup allows AI coding agents to instantly see layout changes without full rebuilds, significantly speeding up the development loop.

If you work in React Native or web, you're used to development feeling fast. You save, and the change is there. In native Swift, checking one UI change still means a full rebuild.

When I first thought about hot reload for Swift, I was thinking about it from a developer perspective. I wanted UI iteration to feel instant, especially when you're dialing in a screen's layout and visual details.

But then I soon realized all of us use agents to work through most things at this point. In agent workflows, verification is a really important step, and in Swift that's the slow part.

So I set up hot reload for Swift, built to speed up agentic development and make that verification much, much faster. Checking a one-line UI edit on a large iOS app can take minutes. Now most saves show up in about a second, on the same screen with the same state, and my coding agents use it by default for UI work.

Here's how it works, including what still needs a rebuild.

The problem

Checking one visual change in a UIKit app means rebuild, install, relaunch, then tapping back to the screen. On a large project, a one-line layout edit can easily take minutes to verify. Every relaunch also throws away state: auth flows reset, scroll positions jump back to the top, and open sheets disappear.

When every check takes a minute or more, agents do one of two things. They spend most of their time waiting, or they batch a bunch of edits into one build and then can't tell which one broke the layout.

For an agent, that rebuild time is the verification step, and it comes after every change. That's the loop I wanted to make fast.

The numbers

On a large app I worked on, a one-line edit used to take 55 seconds through a rebuild. With hot reload, the first save of a file takes about 7.9 seconds and every save after that takes about 0.9 seconds. The app never leaves the screen you're on.

There's a cost. Hot reload builds can't use Xcode's compilation cache, so a cold build is about 10% slower. It pays off from the second edit.

How it works

1. A link flag

Hot reload builds link with -interposable. That makes function calls go through a table of addresses, so a function can be swapped by changing one entry. I only pass it on the command line for hot reload builds. Normal debug builds link exactly like before.

bash
1OTHER_LDFLAGS="-Xlinker -interposable"
2EMIT_FRONTEND_COMMAND_LINES=YES

2. An engine

The engine is InjectionLite, an open source, MIT licensed package by John Holdsworth, the same person behind InjectionIII. Simulator apps are ordinary Mac processes, so it can watch your source folders directly.

When you save a file, it finds that file's exact swiftc command in Xcode's build log, recompiles just that file into a small dylib, loads it into the running app, and points the call table and class vtables at the new code.

3. An app hook

When a reload lands, a small debug-only helper walks every window and on-screen view controller and marks them dirty: setNeedsLayout, setNeedsDisplay, and the screen's own render method. On the next frame, UIKit runs layout, drawing and render on the same objects with the same state, now running the new code.

A little pill at the top of the screen says "Reloaded File.swift · 474 ms" or "File.swift didn't compile". If it didn't compile, the app keeps running the last good code.

Making it work for agents

A fast reload only helps an agent if it can tell what happened, so the result has to be something it can read.

My first try worked, but it was fragile. It silently dropped the first save after every launch, and it only printed to the app console, so an agent had no idea whether a save reloaded, failed or got ignored. It also linked the engine into the app itself, which risked a live file watcher ending up in a TestFlight build.

So I changed a few things.

Inserted, not linked. InjectionLite plus a small shim get built into one simulator-only dylib that starts itself. The launch script injects it with DYLD_INSERT_LIBRARIES, so the app binary never contains it and beta and release builds can't carry it.

bash
1SIMCTL_CHILD_DYLD_INSERT_LIBRARIES=/path/to/hotreload.dylib \
2 xcrun simctl launch booted <your.app.id>

Results a machine can read. InjectionLite only prints prose. The shim hooks its compile and load events and writes one JSON log line per save, plus the in-app pill.

A wait command. The agent saves a file, then runs a command that waits until the app reports on that save. Exit 0 means it reloaded. Exit 1 means it didn't compile, with errors at file:line. A timeout comes with a hint. It matches on a reload after the file's last write, so calling it late is fine.

Works from the first save. The launcher waits for the engine to say it's watching, then writes one throwaway file, so the save the engine drops after launch is never a real one.

One worktree at a time. Only the worktree that launched the app gets watched, so agents working in parallel worktrees never reload into each other's simulators.

Agents get one flag on the launch command, and I added a short guide to my agent instructions on when to reload and when to rebuild.

What reloads and what needs a rebuild

This is the part that matters most, because agents need to know which edits a reload actually covers.

  • Instant: layout, drawing and the render method. Frames, spacing, colors, fonts, copy, show and hide logic.
  • Next call: view models, presentation and shared logic. Sorting, formatting, computed properties, tap handlers written as methods.
  • On revisit: init, viewDidLoad, setup code, closures stored during setup, lazy and cached values. Leave the screen and come back.
  • Rebuild: changing a type's shape (a stored property, an enum case, a function signature), generic types, launch-time code, asset and string catalogs, xcconfigs, Package.swift and macros. Generics need a rebuild because the compiler specializes them per call site, so there's no single function to swap.

My rule of thumb:

if you changed what code does and it runs again, it reloads. If you changed what something is, rebuild.

One catch. "Reloaded" doesn't mean the edit was safe to reload. Add a stored property and it still says reloaded, then the app shows stale state or crashes. So agents decide reload or rebuild before they save, not after.

Upkeep

InjectionLite follows Xcode closely, so expect to bump it with most major Xcode versions. It has one maintainer, so I pin the version. If a release goes bad, hot reload breaks, not the app.

Builds started with Xcode's Run button don't log compiler commands for Swift packages, so that path still needs the InjectionNext app.

Try it in your own app

If you want to wire this up in your own iOS repo, paste this prompt into your coding agent:

text
1Set up simulator-only Swift hot reload for this iOS app so coding agents can verify UI edits in about a second without linking anything into the app binary.
2
31. Hot reload build flags: add a dev launch mode that passes OTHER_LDFLAGS="-Xlinker -interposable", EMIT_FRONTEND_COMMAND_LINES=YES, disables Xcode's compilation cache, and passes -resultBundlePath so xcodebuild writes a full build log. Keep normal debug, beta, and release builds untouched.
42. Separate injected dylib: build InjectionLite (https://github.com/johnno1962/InjectionLite, pinned to a specific release) plus a small shim into one simulator-only dylib, and inject it at launch via SIMCTL_CHILD_DYLD_INSERT_LIBRARIES. Do not link it into the app target.
53. App refresh hook: in a debug-only helper, walk visible windows and view controllers on reload and trigger setNeedsLayout, setNeedsDisplay, and any screen render hook (or SwiftUI refresh if using SwiftUI). Show a small top-of-screen status pill with reload timing or compile errors.
64. Machine-readable output and wait script: have the shim write one JSON line per compile/load event to a host-readable log file (avoid simctl --stdout=/tmp paths, which write inside the simulator container), using DispatchQueue.main.async to stay ordered with InjectionLite. Add a wait script that blocks until a reload is logged after a file's mtime, returning exit 0 on reload, exit 1 with file:line errors on compile failure, and a hint on timeout.
75. First-save warmup and worktree isolation: after launch, wait for the engine's watching signal and touch one throwaway file so the dropped first save is never a real edit. Scope file watching strictly to the current git worktree.
86. Agent guide: add a short section to the repo's agent instructions listing what hot-reloads (layout, styling, method bodies, next-call logic) vs what requires a rebuild (stored properties, enum cases, function signatures, generics, assets, Package.swift, macros, and final PR verification).

Where it stands

Now my agents use hot reload by default when they work on UI, and only rebuild for edits it can't reload.

I started this to speed up UI iteration, and it ended up being about letting agents verify their own work fast. If you try this in your own repo, lmk how it goes! Would love any feedback or ideas on how to make it better 🙏🏼

One-click save

Use YouMind for AI deep reading of viral articles

Save the source, ask focused questions, summarize the argument, and turn a viral article into reusable notes in one AI workspace.

Explore YouMind
For creators

Turn your Markdown into a clean 𝕏 article

When you publish your own long-form writing, images, tables, and code blocks make 𝕏 formatting painful. YouMind turns a full Markdown draft into a clean, ready-to-post 𝕏 article.

Try Markdown to 𝕏

More patterns to decode

Recent viral articles

Explore more viral articles