I was brushing up on SwiftUI for interviews and had an idea — could an LLM generate SwiftUI on the fly and render native UI at runtime?

Swift doesn't support runtime code compilation, so I had to get creative. Instead of trying to interpret Swift code, I designed a constrained Domain-Specific Language — about 12 node types that the LLM outputs as JSON.

The approach

The components include:

The app recursively processes this JSON tree and maps each node to actual SwiftUI views. The key insight was keeping the LLM "within the sandbox" — giving it enough flexibility to be creative while constraining it enough to be reliable.

What it looks like in practice

You can ask natural language questions about your data, and the app generates unique layouts in real time — charts, stats, transaction lists — no hardcoded screens required. Every response is a different layout tailored to the question.

Where it breaks

I'll be honest — the demo has edge cases where the UI can break in weird ways due to formatting issues. Production readiness would require a larger component library, better error handling, and a lot more prompt engineering.

But the core idea works. And it's genuinely fun to use.

Check it out

The code is on GitHub if you want to poke around. Would love to hear what people think — especially if you've tried something similar.