Communitygithub.com

FoundationModels:裝置端大型語言模型(iOS 26)

使用 Apple FoundationModels 框架在裝置端整合 LLM,支援文字生成、使用 @Generable 進行引導式生成、工具呼叫與快照串流,適用於 iOS 26+。

FoundationModels:裝置端大型語言模型(iOS 26) 是什麼?

這份指南詳細說明如何在 iOS 應用程式中,利用 Apple 的 FoundationModels 框架整合裝置端語言模型。其核心價值在於「隱私保護」與「離線運作」:所有資料處理都不離開裝置,無需仰賴雲端服務。支援多種應用模式:基礎文字生成與多輪對話(透過 session 管理)、使用 `@Generable` 巨集進行結構化輸出(定義如 `CatProfile` 等 Swift 型別,並以 `@Guide` 約束範圍或數量)、自訂工具呼叫(讓模型呼叫如 `RecipeSearchTool` 等特定領域的 Swift 功能),以及即時快照串流(透過 `PartiallyGenerated` 型別逐步更新 UI)。文件強調實作前的「可用性檢查」(檢查 `model.availability`,處理裝置資格、Apple Intelligence 開關與模型下載狀態)、單一 session 的請求管理(避免併發請求),以及 4,096 token 限制。適合開發隱私敏感的 AI 功能、結構化資料萃取與離線 AI 助理。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/foundation-models-on-device

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

FoundationModels:裝置端大型語言模型(iOS 26) 是做什麼的?

使用 FoundationModels 框架將 Apple 的裝置端語言模型整合至 App 的模式。涵蓋文字生成、使用 @Generable 進行結構化輸出、自訂工具呼叫與快照串流——所有操作均在裝置端執行,以確保隱私與離線支援。

何時啟用

  • 使用 Apple Intelligence 在裝置端打造 AI 功能
  • 需要在無雲端依賴下產生或摘要文字
  • 從自然語言輸入中萃取結構化資料
  • 為特定領域的 AI 動作實作自訂工具呼叫
  • 串流結構化回應以實現即時 UI 更新
  • 需要注重隱私的 AI(資料不離開裝置)

核心模式 — 可用性檢查

在建立 session 之前,務必檢查模型可用性:

struct GenerativeView: View {
    private var model = SystemLanguageModel.default

    var body: some View {
        switch model.availability {
        case .available:
            ContentView()
        case .unavailable(.deviceNotEligible):
            Text("此裝置不符合 Apple Intelligence 資格")
        case .unavailable(.appleIntelligenceNotEnabled):
            Text(

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能