What problem does it solve?
This Skill helps developers implement on-device AI with Apple's Foundation Models framework while avoiding common pitfalls like context overflow, blocking the UI, manual JSON parsing, and using the model for inappropriate tasks (e.g., world knowledge).
Core Features & Use Cases
- Anti-Pattern Prevention: Identifies and corrects common mistakes such as using the model for world knowledge, blocking the main thread, or ignoring availability checks.
- Structured Output with @Generable: Guides on using the
@Generable macro for type-safe, guaranteed structured output, eliminating manual JSON parsing and runtime errors.
- Context & Tool Management: Strategies for handling context window limits, implementing tool calling for external data, and optimizing performance with streaming and prewarming.
- Use Case: When you need to extract structured data from an invoice using the on-device model, use this skill to define an
@Generable struct for the invoice fields, ensuring type-safe and error-free data extraction.
Quick Start
Before writing any Foundation Models code, check availability with switch SystemLanguageModel.default.availability { case .available: print("✅ Foundation Models available") case .unavailable(let reason): print("❌ Unavailable: \(reason)") } to ensure the feature can run on the user's device.