Foundation models 怎么用
Asked on 06/12/2025
1 search
The Foundation Models framework, introduced by Apple, provides access to an on-device large language model through a convenient Swift API. This framework is available on macOS, iPadOS, iOS, and VisionOS, and it allows developers to enhance their apps with intelligent features while keeping data private and offline.
To use the Foundation Models framework, you can follow these steps:
-
Import the Framework: Start by importing the Foundation Models framework into your project.
-
Create a Session: Initialize a session to interact with the model. This session will handle the communication between your app and the language model.
-
Send Prompts: Use the session to send prompts to the model. You can generate text, structured data, or even use tool calling to perform specific actions.
-
Structured Output: The framework supports generating structured data using the
Generable
macro, which allows you to define Swift types that the model can generate. -
Tool Calling: You can define tools that the model can call to fetch additional information or perform actions, enhancing the model's capabilities beyond text generation.
For a detailed exploration of these features, you can refer to the following sessions from WWDC 2025:
- Deep dive into the Foundation Models framework
- Meet the Foundation Models framework
- Code-along: Bring on-device AI to your app using the Foundation Models framework
These sessions provide comprehensive insights into using the Foundation Models framework, including prompt engineering, tool calling, and generating structured data.

Deep dive into the Foundation Models framework
Level up with the Foundation Models framework. Learn how guided generation works under the hood, and use guides, regexes, and generation schemas to get custom structured responses. We’ll show you how to use tool calling to let the model autonomously access external information and perform actions, for a personalized experience. To get the most out of this video, we recommend first watching “Meet the Foundation Models framework”.

Meet the Foundation Models framework
Learn how to tap into the on-device large language model behind Apple Intelligence! This high-level overview covers everything from guided generation for generating Swift data structures and streaming for responsive experiences, to tool calling for integrating data sources and sessions for context management. This session has no prerequisites.

Platforms State of the Union
Discover the newest advancements on Apple platforms.