如何使用 Foundation Models
Asked on 06/13/2025
1 search
To use Foundation Models, you can leverage the Foundation Models Framework, which 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 you to enhance your apps with intelligent features while keeping data private and running offline.
Here are some key steps and features for using Foundation Models:
-
Import the Framework: Start by importing the Foundation Models framework into your project.
-
Create a Session: Establish a session to interact with the model. This session will manage the state and history of interactions.
-
Prompt the Model: Send prompts to the model to generate responses. You can use simple text prompts or more structured prompts using the
Generable
andGuide
macros to get structured output. -
Tool Calling: Define tools that the model can call autonomously to perform tasks or fetch additional information. This is useful for integrating external data or actions into the model's processing.
-
Guided Generation: Use guided generation to produce structured data that can be directly used in your app. This involves defining types and constraints that the model should adhere to when generating output.
-
Safety and Trust: Implement safety measures and guardrails to ensure the model generates appropriate content and handles user input responsibly.
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 effectively in your applications.

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”.

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

Code-along: Bring on-device AI to your app using the Foundation Models framework
Develop generative AI features for your SwiftUI apps using the Foundation Models framework. Get started by applying the basics of the framework to create an awesome feature. Watch step-by-step examples of how to complement the models with tools you build, stream results, and apply further optimizations for great performance.