How We Built an Interpreter for Swift
Posted4 months agoActive4 months ago
bitrig.appTechstory
excitedpositive
Debate
40/100
SwiftInterpreterIos DevelopmentMobile App Development
Key topics
Swift
Interpreter
Ios Development
Mobile App Development
The Bitrig team built a Swift interpreter that allows dynamic generation and execution of Swift code on iOS devices, sparking interest and questions about its capabilities and potential applications.
Snapshot generated from the HN discussion
Discussion Activity
Moderate engagementFirst comment
58s
Peak period
10
1-2h
Avg / period
4
Comment distribution36 data points
Loading chart...
Based on 36 loaded comments
Key moments
- 01Story posted
Sep 4, 2025 at 12:39 PM EDT
4 months ago
Step 01 - 02First comment
Sep 4, 2025 at 12:40 PM EDT
58s after posting
Step 02 - 03Peak activity
10 comments in 1-2h
Hottest window of the conversation
Step 03 - 04Latest activity
Sep 5, 2025 at 12:09 AM EDT
4 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45129160Type: storyLast synced: 11/20/2025, 12:53:43 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
Does SwiftUI have properties that uniquely make this type of interpreted system possible, or could it also use UIKit under the hood? On the surface, it seems like UIKit might be more difficult since you’d probably need to parse all of the obj-c header files in addition to the .swiftinterface.
Very cool stuff, excited to follow along how you all develop the product!
We're very interested in using the interpreter to improve the Swift developer experience in more ways like that.
>To make it possible to instantly run your app, we built a Swift interpreter. But it’s an unusual interpreter, since it interprets from Swift… to Swift.
I can't understand what they're talking about, and I don't know if it's because I know too little about programming languages or if it's because they're using unusual semantics.
"a compiled language" makes no sense to me because the language itself doesn't determine whether it's compiled or interpreted. It's just a function of what compilers/interpreters exist. I could write an interpreter for C or a compiler for Python, but the languages themselves aren't compiled or interpreted.
I also don't understand what it means to "interpret" Swift to Swift. Do they mean they compile Swift to Swift (or the more modern "transpile" which means the same thing)? But it sounds like they're doing something dynamically at runtime, so it sounds more like decompiling machine code back to Swift, but the rest of the post doesn't match that interpretation.
Bitrig runs Swift apps which are dynamically generated by an LLM on the iPhone, despite the iPhone strict security provisions (e.g. inability to write executable pages of memory). The way we do this is by parsing the generated Swift code and mapping that to the compiled calls to the libraries that come in the OS. It's pretty weird, but we think it's worth it to get the ability to immediately render the generated code on the phone.
I think that's a more accessible explanation. Consider folding that into the article's introduction.
Is the idea that your interpreter is signed, and then you translate the user's arbitrary unsigned Swift code into calls to other already-signed code that ships with iOS?
My understanding is that this system walks the syntax, creates autogenerated wrappers to API structures/functions, and simply invokes them as the syntax directs – as it says, a "glorified FFI". It is not a full free-standing Swift runtime, but it's a very clever hack.
What's the performance like?
The places you can hit performance issues are things like when the app itself has a tight loop that's doing a lot of work.
Section 2.5.2 in "App Review Guidelines" (https://developer.apple.com/app-store/review/guidelines/):
In a sense, this isn't very different from what React Native does (run interpreted code that calls out into native code), just with Swift instead of JavaScript. There used to be JavaScript-specific requirements in the guidelines, but that has been loosened since Swift Playgrounds was released. Now there are Python IDEs, Jupyter Notebooks, and other apps running arbitrary code in the App Store.
We also have functionality in bitrig to build your app and send it to App Store Connect so you can deploy it on TestFlight.