Apple Foundation Models · SwiftUI
The Apple Foundation Models starter kit for iOS
Ship Apple Intelligence features without burning a week on on-device debugging. Get a production wrapper for Foundation Models — streaming chat, typed @Generable output, and a tool-calling agent — with the Swift 6 concurrency and availability edge cases already solved. A secure cloud AI fallback is built in for when you need a bigger model.
On-device LLM, done right
A LanguageModelSession wrapper with streaming responses and full availability handling: device eligibility, Apple Intelligence status, model readiness, guardrail and context-overflow recovery.
Structured output + agents
Typed results via @Generable instead of fragile string parsing, plus a tool-calling on-device agent with example tools (weather, calculator, calendar) you can extend.
Secure cloud fallback
When you need a bigger model, ChatGPT, DALL·E, and Vision are proxied through an HMAC-signed backend so your API keys never ship in the app — and the app still works on non-eligible devices.
What you skip
The Foundation Models layer that AI code generators get subtly wrong, already implemented and device-tested:
Services/AI/ LocalLLMService.swift // sessions, streaming, availability, errors Agent/OnDeviceAgent.swift // tool-calling loop over the transcript Tools/ // Weather, Calculator, Calendar, Reminders Views/AI/ Chat/ // streaming chat UI Structured/ // @Generable typed output (e.g. TripPlanner) Agent/ // multi-tool agent UI
FAQ
What is Apple's Foundation Models framework?
Foundation Models is Apple's on-device large language model framework, introduced with Apple Intelligence. It lets your app run text generation, summarization, structured extraction, and tool-calling entirely on the device — no server, no API keys, no per-token cost, and no data leaving the phone. This kit ships a production wrapper (LocalLLMService) around it so you skip the setup and edge cases.
What does the kit actually include for Foundation Models?
A LanguageModelSession wrapper with streaming responses, @Generable structured output (typed results instead of string parsing), a tool-calling on-device agent with example tools (weather, calculator, calendar), and complete availability handling — device-not-eligible, Apple Intelligence-not-enabled, model-not-ready, guardrail and context-overflow recovery. It also includes a secure cloud AI stack (ChatGPT, DALL·E, Vision) behind an HMAC-signed proxy for when you need a bigger model.
Why not just ask ChatGPT or Cursor to generate this?
You can generate the SwiftUI scaffolding in minutes — that part is easy. The hard part is the Foundation Models glue: correct Swift 6 actor isolation for partial streaming (a non-Sendable PartiallyGenerated crossing isolation boundaries is a common crash), availability modeling, and tool-calling wiring. That is exactly where AI produces plausible-but-broken code that costs days of on-device debugging. This kit is the known-correct, device-tested version.
Which iOS version and devices are required?
The on-device Foundation Models features require iOS 26 (or later) on Apple Intelligence-capable devices, and the kit degrades gracefully where the model is unavailable — falling back to the secure cloud AI stack so your app still works everywhere. The rest of the kit (auth, payments, analytics) supports earlier iOS versions.