Integrate on-device LLM generation, tool calling, and streaming in iOS apps.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "foundation-models-on-device" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/foundation-models-on-device/SKILL.md 2. Save it as ~/.claude/skills/foundation-models-on-device/SKILL.md 3. Reload skills and tell me it's ready
Write a Swift example for iOS 26+ using Apple’s FoundationModels framework to demonstrate basic text generation, including model invocation, prompt input, result display, and a code structure suitable for a SwiftUI app.
A practical Swift/SwiftUI sample showing how to integrate on-device text generation into an app.
Using Apple’s FoundationModels framework, show how to use @Generable for structured output by generating a meeting-notes object with title, summary, action items, and owners, and provide a complete Swift example.
An example with an @Generable data model and invocation code for reliable structured generation.
Demonstrate tool calling and snapshot streaming with Apple’s FoundationModels framework: define a weather-fetching tool, let the model call it based on a user query, and stream intermediate and final results in real time using Swift.
A Swift implementation showing tool definition, model invocation, and streaming UI updates.
Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with @Generable, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.
Always check model availability before creating a session:
struct GenerativeView: View {
private var model = SystemLanguageModel.default
var body: some View {
switch model.availability {
case .available:
ContentView()
case .unavailable(.deviceNotEligible):
Text("Device not eligible for Apple Intelligence")
case .unavailable(.appleIntelligenceNotEnabled):
Text("Please enable Apple Intelligence in Settings")
case .unavailable(.modelNotReady):
Text("Model is downloading or not ready")
case .unavailable(let other):
Text("Model unavailable: \(other)")
}
}
}
// Single-turn: create a new session each time
let session = LanguageModelSession()
let response = try await session.respond(to: "What's a good month to visit Paris?")
print(response.content)
// Multi-turn: reuse session for conversation context
let session = LanguageModelSession(instructions: """
You are a cooking assistant.
Provide recipe suggestions based on ingredients.
Keep suggestions brief and practical.
""")
let first = try await session.respond(to: "I have chicken and rice")
let followUp = try await session.respond(to: "What about a vegetarian option?")
Key points for instructions:
Generate structured Swift types instead of raw strings:
@Generable(description: "Basic profile information about a cat")
struct CatProfile {
var name: String
@Guide(description: "The age of the cat", .range(0...20))
var age: Int
@Guide(description: "A one sentence profile about the cat's personality")
var profile: String
}
let response = try await session.respond(
to: "Generate a cute rescue cat",
generating: CatProfile.self
)
// Access structured fields directly
print("Name: \(response.content.name)")
print("Age: \(response.content.age)")
print("Profile: \(response.content.profile)")
.range(0...20) — numeric range.count(3) — array element countdescription: — semantic guidance for generationLet the model invoke custom code for domain-specific tasks:
struct RecipeSearchTool: Tool {
let name = "recipe_search"
let description = "Search for recipes matching a given term and return a list of results."
@Generable
struct Arguments {
var searchTerm: String
var numberOfResults: Int
}
func call(arguments: Arguments) async throws -> ToolOutput {
let recipes = await searchRecipes(
term: arguments.searchTerm,
limit: arguments.numberOfResults
)
return .string(recipes.map { "- \($0.name): \($0.description)" }.joined(separator: "\n"))
}
}
…
Coordinate behavior-preserving code refactors with tests, review, and gated commits.
Operate long-running agent workloads with monitoring, security, and lifecycle control.
Build a motion foundation for React/Next.js with safe, accessible performance rules.
Unify multi-channel notifications for routing, deduplication, escalation, and inbox consolidation.
Generate or audit design systems and review styling consistency changes.
Learn SwiftUI architecture, state management, navigation, and performance best practices.
Use Apple on-device foundation models for generation, summarization, and classification.
Access Apple on-device models on macOS for generation, structured output, and chat.
Run multimodal AI locally on Android for chat, vision, transcription, and image generation.
Helps developers validate, build, and optimize apps for Apple platforms.
Build, run, and test apps in the iOS Simulator more efficiently.
Search Apple developer docs, APIs, code samples, and WWDC content in AI assistants.