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:
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.
Access the General-Purpose On-Device Model
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.
Recommended by LinkedIn
An alternative way to prompt the model is to open any Swift file of your Xcode 26 project, add the Playground macro, create a session, and generate a response.
import FoundationModels
import Playgrounds
#Playground {
let session = LanguageModelSession()
let response = try await session.respond(to: "Tell me a story")
}
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.
Running the sample Playground in Xcode 26 should provide an output similar to this image.
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.
struct GenerativeView: View {
// Create a reference to the system language model.
private var model = SystemLanguageModel.default
var body: some View {
switch model.availability {
case .available:
// Show your intelligence UI.
case .unavailable(.deviceNotEligible):
// Show an alternative UI.
case .unavailable(.appleIntelligenceNotEnabled):
// Ask the person to turn on Apple Intelligence.
case .unavailable(.modelNotReady):
// The model isn't ready because it's downloading or because of other system reasons.
case .unavailable(let other):
// The model is unavailable for an unknown reason.
}
}
}
You may also want to generate a response by specifying detailed instructions as follows:
let instructions = """
Suggest five related topics. Keep them concise (three to seven words) and make sure they \
build naturally from the person's topic.
"""
let session = LanguageModelSession(instructions: instructions)
let prompt = "Making homemade bread"
let response = try await session.respond(to: prompt)
Lastly, you could try fine-tuning the model's output with different generation options to get accurate and satisfying results.
let options = GenerationOptions(temperature: 2.0)
let session = LanguageModelSession()
let prompt = "Write me a story about coffee."
let response = try await session.respond(
to: prompt,
options: options
)
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.