$npx -y skills add johnrogers/claude-swift-engineering --skill foundation-modelsUse when implementing on-device AI with Apple's Foundation Models framework (iOS 26+), building summarization/extraction/classification features, or using @Generable for type-safe structured output.
| 1 | # Foundation Models |
| 2 | |
| 3 | Apple's on-device AI framework providing access to a 3B parameter language model for summarization, extraction, classification, and content generation. Runs entirely on-device with no network required. |
| 4 | |
| 5 | ## Overview |
| 6 | |
| 7 | Foundation Models enable intelligent text processing directly on device without server round-trips, user data sharing, or network dependencies. The core principle: leverage on-device AI for specific, contained tasks (not for general knowledge). |
| 8 | |
| 9 | ## Reference Loading Guide |
| 10 | |
| 11 | **ALWAYS load reference files if there is even a small chance the content may be required.** It's better to have the context than to miss a pattern or make a mistake. |
| 12 | |
| 13 | | Reference | Load When | |
| 14 | |-----------|-----------| |
| 15 | | **[Getting Started](references/getting-started.md)** | Setting up LanguageModelSession, checking availability, basic prompts | |
| 16 | | **[Structured Output](references/structured-output.md)** | Using `@Generable` for type-safe responses, `@Guide` constraints | |
| 17 | | **[Tool Calling](references/tool-calling.md)** | Integrating external data (weather, contacts, MapKit) via Tool protocol | |
| 18 | | **[Streaming](references/streaming.md)** | AsyncSequence for progressive UI updates, PartiallyGenerated types | |
| 19 | | **[Troubleshooting](references/troubleshooting.md)** | Context overflow, guardrails, errors, anti-patterns | |
| 20 | |
| 21 | ## Core Workflow |
| 22 | |
| 23 | 1. Check availability with `SystemLanguageModel.default.availability` |
| 24 | 2. Create `LanguageModelSession` with optional instructions |
| 25 | 3. Choose output type: plain String or @Generable struct |
| 26 | 4. Use streaming for long generations (>1 second) |
| 27 | 5. Handle errors: context overflow, guardrails, unsupported language |
| 28 | |
| 29 | ## Model Capabilities |
| 30 | |
| 31 | | Use Case | Foundation Models? | Alternative | |
| 32 | |----------|-------------------|-------------| |
| 33 | | Summarization | Yes | - | |
| 34 | | Extraction (key info) | Yes | - | |
| 35 | | Classification | Yes | - | |
| 36 | | Content tagging | Yes (built-in adapter) | - | |
| 37 | | World knowledge | No | ChatGPT, Claude, Gemini | |
| 38 | | Complex reasoning | No | Server LLMs | |
| 39 | |
| 40 | ## Platform Requirements |
| 41 | |
| 42 | - iOS 26+, macOS 26+, iPadOS 26+, visionOS 26+ |
| 43 | - Apple Intelligence-enabled device (iPhone 15 Pro+, M1+ iPad/Mac) |
| 44 | - User opted into Apple Intelligence |
| 45 | |
| 46 | ## Common Mistakes |
| 47 | |
| 48 | 1. **Using Foundation Models for world knowledge** — The 3B model is trained for on-device tasks only. It won't know current events, specific facts, or "who is X". Use ChatGPT/Claude for that. Keep prompts to: summarizing user's own content, extracting info, classifying text. |
| 49 | |
| 50 | 2. **Blocking the main thread** — LanguageModelSession calls must run on a background thread or async context. Blocking the main thread locks UI. Always use `Task { }` or background queue. |
| 51 | |
| 52 | 3. **Ignoring context overflow** — The model has finite context. If the user pastes a 50KB document, it will fail silently or truncate. Check input length and trim/truncate proactively. |
| 53 | |
| 54 | 4. **Forgetting to check availability** — Not all devices support Foundation Models. Check `SystemLanguageModel.default.availability` before using. Graceful degradation is required. |
| 55 | |
| 56 | 5. **Ignoring guardrails** — The model won't answer harmful queries. Instead of fighting it, design prompts that respect safety guidelines. Rephrasing requests usually works. |