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"))
}
}
…
Apply Compose Multiplatform patterns for UI architecture, navigation, theming, and performance.
Set up and manage Pi-hole DNS, blocking, and home network resolution.
Translate visa document images into English and generate a bilingual PDF.
Create animation-rich web presentations or convert PowerPoint decks for talks and pitches.
Orchestrate RFC-based multi-agent workflows with quality gates and merge queues.
Optimize React and Next.js performance during coding, review, and refactoring.
Use Apple on-device foundation models for generation, summarization, and classification.
Run multimodal AI locally on Android for chat, vision, transcription, and image generation.
Fetch Apple docs, analyze Xcode errors, and verify Swift Evolution proposals.
Build modern iOS app features with Swift, SwiftUI, and Apple frameworks.
Give AI coding agents live simulator, browser screenshots, and logs context.
Convert Apple developer docs and WWDC content into AI-ready Markdown.