apple-on-device-ai▌
dpearson2699/swift-ios-skills · updated Apr 8, 2026
MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.
Deploy on-device AI across Apple platforms using Foundation Models, Core ML, MLX Swift, and llama.cpp.
- ›Choose Foundation Models for zero-setup text generation and structured output on iOS 26+; Core ML for custom vision and NLP models; MLX Swift for maximum throughput on Apple Silicon; llama.cpp for cross-platform GGUF inference
- ›Foundation Models includes session management, @Generable macros for type-safe structured output, tool calling, and streaming with always-enforced guardrails
On-Device AI for Apple Platforms
Guide for selecting, deploying, and optimizing on-device ML models. Covers Apple Foundation Models, Core ML, MLX Swift, and llama.cpp.
Contents
- Framework Selection Router
- Apple Foundation Models Overview
- Core ML Overview
- MLX Swift Overview
- Multi-Backend Architecture
- Performance Best Practices
- Common Mistakes
- Review Checklist
- References
Framework Selection Router
Use this decision tree to pick the right framework for your use case.
Apple Foundation Models
When to use: Text generation, summarization, entity extraction, structured output, and short dialog on iOS 26+ / macOS 26+ devices with Apple Intelligence enabled. Zero setup -- no API keys, no network, no model downloads.
Best for:
- Generating text or structured data with
@Generabletypes - Summarization, classification, content tagging
- Tool-augmented generation with the
Toolprotocol - Apps that need guaranteed on-device privacy
Not suited for: Complex math, code generation, factual accuracy tasks, or apps targeting pre-iOS 26 devices.
Core ML
When to use: Deploying custom trained models (vision, NLP, audio) across all Apple platforms. Converting models from PyTorch, TensorFlow, or scikit-learn with coremltools.
Best for:
- Image classification, object detection, segmentation
- Custom NLP classifiers, sentiment analysis models
- Audio/speech models via SoundAnalysis integration
- Any scenario needing Neural Engine optimization
- Models requiring quantization, palettization, or pruning
MLX Swift
When to use: Running specific open-source LLMs (Llama, Mistral, Qwen, Gemma) on Apple Silicon with maximum throughput. Research and prototyping.
Best for:
- Highest sustained token generation on Apple Silicon
- Running Hugging Face models from
mlx-community - Research requiring automatic differentiation
- Fine-tuning workflows on Mac
llama.cpp
When to use: Cross-platform LLM inference using GGUF model format. Production deployments needing broad device support.
Best for:
- GGUF quantized models (Q4_K_M, Q5_K_M, Q8_0)
- Cross-platform apps (iOS + Android + desktop)
- Maximum compatibility with open-source model ecosystem
Quick Reference
| Scenario | Framework |
|---|---|
| Text generation, zero setup (iOS 26+) | Foundation Models |
| Structured output from on-device LLM | Foundation Models (@Generable) |
| Image classification, object detection | Core ML |
| Custom model from PyTorch/TensorFlow | Core ML + coremltools |
| Running specific open-source LLMs | MLX Swift or llama.cpp |
| Maximum throughput on Apple Silicon | MLX Swift |
| Cross-platform LLM inference | llama.cpp |
| OCR and text recognition | Vision framework |
| Sentiment analysis, NER, tokenization | Natural Language framework |
| Training custom classifiers on device | Create ML |
Apple Foundation Models Overview
On-device language model optimized for Apple Silicon. Available on devices supporting Apple Intelligence (iOS 26+, macOS 26+).
- Token budget covers input + output; check
contextSizefor the limit - Check
supportedLanguagesfor supported locales - Guardrails always enforced, cannot be disabled
Availability Checking (Required)
Always check before using. Never crash on unavailability.
import FoundationModels
switch SystemLanguageModel.default.availability {
case .available:
// Proceed with model usage
case .unavailable(.appleIntelligenceNotEnabled):
// Guide user to enable Apple Intelligence in Settings
case .unavailable(.modelNotReady):
// Model is downloading; show loading state
case .unavailable(.deviceNotEligible):
// Device cannot run Apple Intelligence; use fallback
default:
// Graceful fallback for any other reason
}
Session Management
// Basic session
let session = LanguageModelSession()
// Session with instructions
let session = LanguageModelSession {
"You are a helpful cooking assistant."
}
// Session with tools
let session = LanguageModelSession(
tools: [weatherTool, recipeTool]
) {
"You are a helpful assistant with access to tools."
}
Key rules:
- Sessions are stateful -- multi-turn conversations maintain context automatically
- One request at a time per session (check
session.isResponding) - Call
session.prewarm()before user interaction for faster first response - Save/restore transcripts:
LanguageModelSession(model: model, tools: [], transcript: savedTranscript)
Structured Output with @Generable
The @Generable macro creates compile-time schemas for type-safe output:
@Generable
struct Recipe {
@Guide(description: "The recipe name")
var name: String
@Guide(description: "Cooking steps", .count(3))
var steps: [String]
@Guide(description: "Prep time in minutes", .range(1...120))
var prepTime: Int
}
let response = try await session.respond(
to: "Suggest a quick pasta recipe",
generating: Recipe.self
)
print(response.content.name)
@Guide Constraints
| Constraint | Purpose |
|---|---|
description: |
Natural language hint for generation |
.anyOf([values]) |
Restrict to enumerated string values |
.count(n) |
Fixed array length |
.range(min...max) |
Numeric range |
.minimum(n) / .maximum(n) |
One-sided numeric bound |
.minimumCount(n) / .maximumCount(n) |
Array length bounds |
.constant(value) |
Always returns this value |
.pattern(regex) |
String format enforcement |
.element(guide) |
Guide applied to each array element |
Properties generate in declaration order. Place foundational data before dependent data for better results.
Streaming Structured Output
let stream = session.streamResponse(
to: "Suggest a recipe",
generating: Recipe.self
)
for try await snapshot in stream {
// snapshot.content is Recipe.PartiallyGenerated (all properties optional)
if let name = snapshot.content.name { updateNameLabel(name) }
}
Tool Calling
struct WeatherTool: Tool {
let name = "weather"
let description = "Get current weather for a city."
@Generable
struct Arguments {
@Guide(description: "The city name")
var city: String
}
func call(arguments: Arguments) async throws -> String {
let weather = try await fetchWeather(arguments.city)
return weather.description
}
}
Register tools at session creation. The model invokes them autonomously.
Error Handling
do {
let response = try await session.respond(to: prompt)
} catch let error as LanguageModelSession.GenerationError {
switch error {
case .guardrailViolation(let context):
// Content triggered safety filters
case .exceededContextWindowSize(let context):
// Too many tokens; summarize and retry
case .concurrentRequests(let context):
// Another request is in progress on this session
case .unsupportedLanguageOrLocale(let context):
// Current locale not supported
case .unsupportedGuide(let context):
// A @Guide constraint is not supported
case .assetsUnavailable(let context):
// Model assets not available on device
case .refusal(let refusal, _):
// Model refused; stream refusal.explanation for details
case .rateLimited(let context)How to use apple-on-device-ai on Cursor
AI-first code editor with Composer
Prerequisites
Before installing skills in Cursor, ensure your development environment meets these requirements:
- ›Cursor installed and configured on your development machine
- ›Node.js version 16.0+ with npm package manager (verify with
node --version) - ›Active project directory or workspace where you want to add apple-on-device-ai
Execute installation command
Execute the skills CLI command in your project's root directory to begin installation:
The skills CLI fetches apple-on-device-ai from GitHub repository dpearson2699/swift-ios-skills and configures it for Cursor.
Select Cursor when prompted
The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:
Verify installation
Confirm successful installation by checking the skill directory location:
Reload or restart Cursor to activate apple-on-device-ai. Access the skill through slash commands (e.g., /apple-on-device-ai) or your agent's skill management interface.
Security & Verification Notice
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.
List & Monetize Your Skill
Submit your Claude Code skill and start earning
Use Cases▌
Task Automation & Efficiency
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Knowledge Enhancement
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Quality Improvement
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
Implementation Guide▌
Prerequisites
- ›Claude Desktop or compatible AI client with skill support
- ›Clear understanding of task or problem to solve
- ›Willingness to iterate and refine outputs
Time Estimate
15-45 minutes depending on use case complexity
Installation Steps
- 1.Install skill using provided installation command
- 2.Test with simple use case relevant to your work
- 3.Evaluate output quality and relevance
- 4.Iterate on prompts to improve results
- 5.Integrate into regular workflow if valuable
Common Pitfalls
- ⚠Expecting perfect results without iteration
- ⚠Not providing enough context in prompts
- ⚠Using skill for tasks outside its intended scope
- ⚠Accepting outputs without review and validation
Best Practices▌
✓ Do
- +Start with clear, specific prompts
- +Provide relevant context and constraints
- +Review and refine all outputs before using
- +Iterate to improve output quality
- +Document successful prompt patterns
✗ Don't
- −Don't use without understanding skill limitations
- −Don't skip validation of outputs
- −Don't share sensitive information in prompts
- −Don't expect skill to replace human judgment
💡 Pro Tips
- ★Be specific about desired format and style
- ★Ask for multiple options to choose from
- ★Request explanations to understand reasoning
- ★Combine AI efficiency with human expertise
When to Use This▌
✓ Use When
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid When
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
Learning Path▌
- 1Familiarize yourself with skill capabilities and limitations
- 2Start with low-risk, non-critical tasks
- 3Progress to more complex and valuable use cases
- 4Build expertise through regular use and experimentation
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.7★★★★★55 reviews- ★★★★★Aanya Singh· Dec 16, 2024
Useful defaults in apple-on-device-ai — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Henry Mensah· Dec 12, 2024
apple-on-device-ai fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Li Okafor· Dec 12, 2024
apple-on-device-ai is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Henry Abebe· Dec 8, 2024
apple-on-device-ai reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Ganesh Mohane· Dec 4, 2024
We added apple-on-device-ai from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Aanya Shah· Nov 27, 2024
We added apple-on-device-ai from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Rahul Santra· Nov 23, 2024
apple-on-device-ai reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Nia Reddy· Nov 7, 2024
Useful defaults in apple-on-device-ai — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Charlotte Robinson· Nov 3, 2024
I recommend apple-on-device-ai for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Anika Mehta· Nov 3, 2024
Keeps context tight: apple-on-device-ai is the kind of skill you can hand to a new teammate without a long onboarding doc.
showing 1-10 of 55