Every year for Halloween, I live-stream a project where I build something that… probably shouldn't exist. A project to be more preoccupied with whether or not I could, where I don’t stop to think if I should. This is the project for Halloween 2024.
This project implements a SwiftUI view that enables you to just place a Swift string describing a view, and that view is built by an LLM (Anthropic's Claude) at runtime. For example:
import SwiftUI
@main
struct Halloween2024App: App {
var body: some Scene {
WindowGroup {
"""
A game of tic-tac-toe you play by clicking each box. Xs should be red and Os should be green. If all the squares are filled, make a snarky comment about how tic-tac-toe is boring.
"""
}
}
}
- Download the project.
- Edit the Halloween2024 scheme.
- Select "Run" in the sidebar.
- Select the "Arguments" tab.
- Add an environment variable named
CLAUDE_API_KEY
with your API key.
- Change the request in
ContentView
to whatever you'd like. - Build and run!
If you want to change what the app does, simply edit the string in ContentView
.
Why would I use this?
Do not use this.
Is it safe to run this on my computer?
Probably not. I had to strip away a lot of the sandboxing and hardened runtime to get this to work. Use at your own risk.
Does this work on iOS?
Not at this time. I think you'd have to have a compiler that ran on a server somewhere to get it to work. If at all.
Can I use a different language model?
Other Claude models are available by swapping the model
parameter in AIService
. Non-Anthropic models are left as an exercise for the reader.
Is this a crime against humanity?
That's for the courts to decide.