Introducing Swapify Agentic hot reload system for iOS now coding agent can see the result of each…
@tornikegomareli2K followers
21,689 views
29 Comments
Comments from the original post on X (Twitter)

@tornikegomareli
A real iPhone was harder, because an iOS process can't write executable memory. There, the patch is built so that dyld binds it to the app's types when it loads. 1.0 to 1.5 s per reload.
4 likes

@tornikegomareli
The slow part of an agent working on an iOS app is the feedback loop. To see what it wrote, it has to build, install, relaunch, and get back to the screen. The app state is lost every time

@tornikegomareli
Swapify replaces the rebuild with a patch. The app is built once with -enable-implicit-dynamic. Then every Swift function starts by checking a pointer in writable data, and jumps to a new body if the pointer names one. Replacing code becomes writing a pointer
1 like

@tornikegomareli
On each save, Swapify compiles only the changed file, with the exact swift-frontend command Xcode used, and links it into a small dylib. The app dlopens it and repoints each changed function. Existing objects, statics and SwiftUI state stay valid

@tornikegomareli
The risk is memory layout. new code runs on objects the app already made. Before loading, Swapify compares the stored properties and vtable of every type. If one differs, nothing loads and the agent is told to rebuild. If the edit doesn't compile, the app keeps running

@tornikegomareli
Then it invalidates SwiftUI's AttributeGraph, as Xcode Previews does, and sends a screenshot and the visible text back to the agent. A warm reload in the simulator 230 ms compile, 210 ms link, 14 ms load, 5 ms redraw, 53 ms screenshot. 512 ms in total

@hyzyla_
@erekle_meskhi @theiskaa @insaneartsio Cool! 🆒
1 like

@hoffinside
@erekle_meskhi @theiskaa @insaneartsio Wild stuff
1 like

@qabbout
@erekle_meskhi @theiskaa @insaneartsio I love what im seeing, great work im gonna try it soon
1 like

@benzhoudev
@erekle_meskhi @theiskaa @insaneartsio does app state survive an edit that adds a new property, or only changes inside the view body?
1 like

@tornikegomareli
@erekle_meskhi @theiskaa @insaneartsio App State survives thats the point

@benzhoudev
@erekle_meskhi @theiskaa @insaneartsio ah then that's the part that sells it 🔥

@nelsondsouzaa
@erekle_meskhi @theiskaa @insaneartsio the faster the agent sees its own result the tighter the loop gets.

@mnooraja
@erekle_meskhi @theiskaa @insaneartsio Is it support uikit?

@tornikegomareli
@erekle_meskhi @theiskaa @insaneartsio Swapify's hot-swap engine works on any Swift code, including UIKit classes, but it only redraws SwiftUI automatically, we will wire up UIKit auto redraw on next release
1 like

@Shubhdhawan1
@erekle_meskhi @theiskaa @insaneartsio How are you hot-reloading the memory layout changes without requiring a full rebuild?

@tornikegomareli
today it doesnt, but the common case (adding a stored property to a class) actually works, i have it running in a prototype idea is to never touch the layout. objects the app already made keep their size and offsets. the new property lives in a side table hanging off each object, kinda like objc associated objects, and gets freed with the object all the work is in the patch's llvm ir. stored field access on a class is always the same shape, a getelementptr on the class struct type. existing fields get their built offsets back, the new field becomes a call that returns its address in the side table. first access on an old object runs the property initializer there non-final classes were the painful part. class metadata puts field offsets before the vtable so one new stored property shifts every method slot. in ir a virtual call is just "load slot 18 from the isa", nothing canay which class its for. SIL does say it tho, every class_method names the class and member. so i compile the patch to SIL too, match its calls to the ir vtable loads in order, existing members go back to the app's slots and calls to new members become direct calls. if anything doesnt match it falls back to a rebuild in the prototype it works for final and non-final classes, a subclass in the same file, and Observable classes (observation tracking still fires for the new prop), without the vtable rewrite the same patch just crashes lol. side effect is that adding a new method on a non-final class reloads too now structs still need a rebuild, a struct copy has no identity to key the side table on. Published and real devices are next in the queue. going into swapify now
1 like

@tornikegomareli
@theiskaa @insaneartsio swapify 0.1.2 can hot reload memory layout as well

@baymax0457983
@erekle_meskhi @theiskaa @insaneartsio 支持UIkit吗还是只支持swiftui

@tornikegomareli
@erekle_meskhi @theiskaa @insaneartsio Swapify's hot-swap engine works on any Swift code, including UIKit classes, but it only redraws SwiftUI automatically, we will wire up UIKit auto redraw on next release.




