HNHacker News
TopNewBestAskShowJobs

jacobx

51 karma · joined August 2, 2021

submissionscomments
jacobx··on Bitrig's Swift Interpreter: From Code to Bytecode
Hi HN! We're back with another post describing more detail about how we built Bitrig's interpreter for Swift in Swift, this time going into how we're converting the code into bytecode.
jacobx··on How we built an interpreter for Swift
Yep! You can always export your code to take it to your computer.

We also have functionality in bitrig to build your app and send it to App Store Connect so you can deploy it on TestFlight.

jacobx··on How we built an interpreter for Swift
We have a Mac app that we're beta testing with our existing subscribers. Is there a reason you want this on iPad instead of the Mac?
jacobx··on How we built an interpreter for Swift
Yeah there was definitely some back and forth about it before we were eventually approved.

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.

jacobx··on How we built an interpreter for Swift
There's definitely a cost: everything is type-erased and there's a lot more indirection than there would be if the code was compiled. But you usually don't hit performance issues because most app code (especially in the UI) is just a thin layer calling into the OS frameworks. The framework code does the heavy lifting and is all compiled.

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.

jacobx··on How we built an interpreter for Swift
I refer to Swift as a "compiled language" because no officially provided interpreter exists for it.

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.

jacobx··on How we built an interpreter for Swift
That's not really been something we'd been considering, but yeah I think we probably could. We're primarily using the interpreter to render SwiftUI views, but it supports running arbitrary Swift expressions or statements.
jacobx··on How we built an interpreter for Swift
I just pushed a change that should fix scrolling on Android browsers.
jacobx··on How we built an interpreter for Swift
Yeah you could! The only caveat is that either the whole app, or at least the part of the app showing the view you want to replace, would have to be running via the interpreter.

We're very interested in using the interpreter to improve the Swift developer experience in more ways like that.

jacobx··on How we built an interpreter for Swift
Thanks for letting us know! We're investigating now.
jacobx··on How we built an interpreter for Swift
Thanks! Yes, it works just as well with UIKit. Fortunately Xcode can synthesize a .swiftinterface for Obj-C frameworks bridged into Swift, so we use that to generate a compiled interface for UIKit (and other Obj-C frameworks).
jacobx··on How we built an interpreter for Swift
Hi HN! Since we launched Bitrig (https://news.ycombinator.com/item?id=45041185), we've gotten questions about how it's able to run dynamically generated Swift code. I wrote up this post to answer that. Let me know if you want to know more about any aspects of it.
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Thanks! Sure, feel free to email us: contact at our domain name.
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yes, we think that could be a really cool way to allow mocking up changes to parts of an app, especially for non-technical members of the team. We're not set up for that yet, but it's on our roadmap.
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Thanks, we'll have to update the Contact Us link to work more generically. The Send Feedback link is when you're inside of a project, and you tap the ... in a circle button. It uploads your feedback and code directly to us, so is the best way for us to directly debug when we're not rendering your code correctly.

I'll take a look at camera access and see what's going wrong there.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Per month
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah this is an area we want to make a lot better. What we're currently thinking is giving the model a way to more explicitly call out that it is adding a call to something that needs an API key, which would add something to the UI to allow you to just paste in your key.

I think there's also work when need to do in the system prompt to guide the model away from all of the placeholder data (or at least so that when it adds it there's a better affordance to transform it to real data).

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
I think that’s a pretty good list. The main one I would add is “creators will want to make native Swift apps to have a better user experience”
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah that’s been my experience too. You can edit the Swift code directly in bitrig, though editing code on a phone is not the best experience. We’ve had a lot of requests for a Mac app. Stay tuned ;)

You can get a compiled build of your app from bitrig: go to Distribute App which will build your app on our server and then upload it to TestFlight for you (this requires a paid Apple Developer Account). This lets you install the compiled app on your Home Screen. You could also always export the code if you want to build it yourself.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
There’s still a lot to do to make this work really great for the Swift ecosystem, and that’s where we have the most expertise, so that’s what we’ll be focused on for now.

That said, we think this same approach could work really well on Android, and it’d be interesting to expand there too.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah we’d love to find a way to give away more in the free tier for hobbyist users and subsidize that with other things. The idea of us putting an ad in unpaid apps as another option is interesting.
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
We’ve gotten a lot of requests for WebKit, so we’ll try to add it soon.

If we hit issues we can try to pull in just a subset, but one nice thing about Swift is the frameworks have .swiftinterface files which list all the APIs in them, so we’ve generally been able to pull in whole frameworks at a time.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah there’s a Send Feedback button when you’re in a project that sends feedback along with the code for that project.

We also have a discord here: https://discord.com/invite/C7ndWKKq2S

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Thanks for trying, sorry you hit that issue!

Could you send us feedback from your project? (Go to the ... menu, then Send Feedback.) If you're not able to use the UI from within your project you can long-press on it from the main screen and choose Recovery Mode, and then enter the project with the interpreter disabled.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Thanks for letting us know, we'll get this fixed in other browsers (we've been just looking at it in Safari).
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Totally agree, we have a lot of ideas for how to make the experience better.
jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
We probably need to make this more discoverable, but if you keep swiping down on the prompt area, you can swipe it completely off screen and your app will be full screen (with a small movable floating button to exit).

I really like the idea of a platform for people sharing mini-apps! It would be great if people could make lightweight specialized apps for different niches and share them with less friction.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah, I think that whole area of dynamically generating UI is really interesting. And having a Swift interpreter like we're using would unlock doing that with native UI components.

Our background is more in making developer tools, so bitrig was the first product we were excited about, but I think there's a lot of overlap with dynamic UI generation, and we'd love to explore that too.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Sorry about that, I reset your free messages for the day, so you should be back at 5.

Moving in and out of the project while messages are sending is a more fragile area of the app and we have some bugs to fix there.

jacobx··on Launch HN: Bitrig (YC S25) – Build Swift apps on your iPhone
Yeah, the prompt is just asking Claude to generate a SwiftUI iPhone app. The recent models have been able to generate really good Swift code, so we just have a set of best practice instructions we've been accumulating (telling it to make an app with @main, pointing it to/away from some APIs, encouraging it to persist things in UserDefaults, etc).

I think most of that would work pretty well for making SwiftUI desktop apps too.

Page 1 of 2Next →