Foundation Models Framework: Quick Start With On-Device AI in Xcode 26
On-device general purpose AI

Foundation Models Framework: Quick Start With On-Device AI in Xcode 26

Apple announced the Foundation Models Framework (FMF) during WWDC25. This tutorial will guide you in quickly interacting with the model to generate text content. Try this incredible on-device generative AI technology on your Apple Silicon Mac and Xcode 26.

Prerequisites

To access the model, download and install the latest versions of Apple's developer tools and operating system on Mac computers with Apple Silicon. Since they are all in beta, you can download them from your Apple Developer account.

Overview

The Foundation Models Framework gives developers access to the underlying language model that powers Apple Intelligence. This large language model has 3 billion parameters. One thing you should remember when working with this LLM is that it is not designed for world knowledge and advanced reasoning. You can use the Swift API on macOS, iOS, iPadOS, and VisionOS to build your AI apps. 

You can utilize this model in many application areas, all on-device:

  • Provide search suggestions in an app.

  • Generative dialog: Create a dialog for game characters.

  • Content generation: Generate text content and use the model to refine it. 

  • In-app user guide: Guide users to use specific features in your app. 

  • Generate quizzes and provide question answering. 

  • Content classification, summarization, and semantic search.

Benefits and Key Features of the On-Device Model

When you access the foundation model, you run it on-device, on your Mac, iPhone, or iPad. This means the data you send in and out of the model stays completely private and secure on your local machine. It is built into your machine's macOS Tahoe so that you can access it offline. 

  • Tool calling: Let the model access a custom code you define in your app to ensure accurate responses. This helps the model obtain additional information and extend its capabilities to improve its results. 

  • Structured output: You can prompt the model to adhere to its responses to guided generation or a JSON format.

  • Streaming partial generations: The model has built-in support for partially generated responses, called snapshots. 

Access the General-Purpose On-Device Model

Create a Swift Playground

To prompt the model for the first time, create a new project in Xcode 26. Then, choose File -> New -> Playground. Select the iOS or macOS template in the window that appears to create a new playground. 

Swift Playground templates for iOS and macOS

An alternative way to prompt the model is to open any Swift file of your Xcode 26 project, add the macro, create a session, and generate a response. 

The sample code above is all you need to prompt the general-purpose language model to generate a text response. You import the required dependencies, initialize a session object, and get a result from the model. 

  • The object interacts with the language model. For more information, refer to the Apple developer documentation

  • Then, to interact with the model with a prompt, you call on the session you initialized. We use an asynchronous response call since the on-device model does not generate its output instantly.

Running the sample Playground in Xcode 26 should provide an output similar to this image. 

Response from the on-device model

You have realized that getting the model up and running requires a few steps. In a real-world scenario, you can check the model’s availability before you instantiate a session to call it. 

You may also want to generate a response by specifying detailed instructions as follows:

Lastly, you could try fine-tuning the model's output with different generation options to get accurate and satisfying results. 

What’s Next? 

This article introduced you to the Foundation Models Framework and how to call it with a prompt in its basic form. It is in its first beta and expected to change over time. In upcoming articles, we will explore the framework's advanced implementations and use cases, such as integrating a custom tool, structured outputs, partial generated responses, tuning generation options, and more. The Apple Developer videos have excellent topics covering the fundamentals and advanced concepts about this framework, such as Meet FMF, On-Device AI With FMF, Prompt Design for FMF, and Deep Dive into FMF.

To view or add a comment, sign in

Others also viewed

Explore topics