How to use Foundation Models?
Asked on 06/25/2025
1 search
To use Foundation Models, you can follow these steps based on the content presented at WWDC:
-
Import the Framework: Start by importing the Foundation Models framework into your project. This gives you access to Apple's on-device large language model.
-
Create a Session: Use the framework to create a session. This session is where you will interact with the model.
-
Send a Prompt: You can send prompts to the model to generate responses. This can be done with just a few lines of code. The model is optimized for tasks like text extraction, summarization, and more.
-
Use Generable for Structured Output: If you need structured output, you can use the
Generable
macro to define types that the model can generate. This allows you to get structured data directly from the model. -
Tool Calling: The framework supports tool calling, which allows the model to autonomously call functions you define. This can be used to fetch additional information or perform actions based on the model's processing.
-
Privacy and Performance: All processing is done on-device, ensuring user data privacy and allowing the model to work offline. The framework is built into the operating system, so it doesn't increase your app size.
For a more detailed exploration, you can refer to the sessions like Deep dive into the Foundation Models framework and Code-along: Bring on-device AI to your app using the Foundation Models framework. These sessions provide in-depth guidance on using the Foundation Models framework effectively.

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

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.

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