At WWDC 2025, Apple amazed the developer community with a new and powerful tool that promises to revolutionize the way we interact with artificial intelligence in mobile and desktop applications: the Foundation Models framework. This framework provides seamless integration of language models and machine learning into iOS, macOS, iPadOS, watchOS, and tvOS apps. In this article, we’ll explore what the Foundation Models framework is, how to use it in SwiftUI and Xcode projects, and go through some practical implementation examples.
What is the Foundation Models Framework?
The Foundation Models framework is a new addition to Apple’s family of frameworks that makes it easier to integrate deep learning (machine learning) and natural language processing (NLP) models into applications. Unlike other machine learning frameworks like Core ML, which allow for the integration of pre-trained models, Foundation Modelsintroduces a new category of pre-trained models for common NLP tasks such as translation, text classification, sentiment analysis, and text generation.
Apple has optimized this framework to be efficient and easy to use, providing support for state-of-the-art models without requiring developers to dive deeply into the mathematics or implementation of neural networks. Additionally, Foundation Models integrates seamlessly with other Apple frameworks like Core ML, SwiftUI, and Combine, making it a robust tool for building intelligent applications.
Key Features of Foundation Models
- Pre-trained Models: Foundation Models includes several pre-trained models that can be used directly in your applications. These models are designed for common natural language processing tasks, such as text classification, sentiment analysis, and text generation.
- Optimized for Apple Silicon: The models are highly optimized to take full advantage of the power of Apple Silicon chips, such as the M1 and M2, delivering impressive performance on Mac and iOS devices.
- Ease of Use: Apple has designed a simple and straightforward API that allows developers to integrate AI into their apps without needing to understand the inner workings of how the models were trained or how neural networks operate.
- Integration with SwiftUI and Xcode: The framework integrates perfectly with Apple’s development tools, making it easy to incorporate AI into visual and dynamic applications using SwiftUI.
- Cross-platform Support: You can use the models on iPhone, iPad, Mac, and Apple Watch, allowing for a consistent experience across all Apple platforms.
How to Start Using Foundation Models in Xcode
To start using Foundation Models in your app, you’ll first need to make sure your development environment is set up. Let’s walk through the basic steps for configuring Xcode and starting a project in SwiftUI.
Step 1: Set Up Your Project in Xcode
- Install Xcode: Make sure you have the latest version of Xcode, which you can download from the Mac App Storeor Apple’s official developer site. You’ll need Xcode 15 or later to access the Foundation Models framework.
- Create a New Project: Open Xcode and select File > New > Project. Choose a project based on SwiftUI.
- Import Foundation Models: In your
ContentView.swiftfile (or any other file where you want to work with AI), import the Foundation Models framework at the top of the file:
import SwiftUI
import FoundationModelsStep 2: Use a Pre-trained Model
Apple has provided several pre-trained models that you can use right away. Let’s look at an example of how to use the sentiment analysis model to analyze a piece of text and determine if the sentiment is positive, negative, or neutral.
Sentiment Analysis Example
- Define the Sentiment Model: Apple provides a pre-trained sentiment analysis model that you can easily load with a high-level API.
- Create a Function to Process Sentiment:
import SwiftUI
import FoundationModels
struct ContentView: View {
@State private var sentiment: String = ""
var body: some View {
VStack {
Text("Sentiment of the text: \(sentiment)")
.padding()
Button(action: analyzeSentiment) {
Text("Analyze Sentiment")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
}
.padding()
}
func analyzeSentiment() {
let model = SentimentAnalysisModel()
// Text to analyze
let text = "Apple is developing amazing technologies."
model.analyze(text: text) { result in
switch result {
case .success(let analysis):
sentiment = analysis.sentimentDescription
case .failure(let error):
sentiment = "Error: \(error.localizedDescription)"
}
}
}
}- n this example, when you press the Analyze Sentiment button, the text is passed through the pre-trained model, and the sentiment analysis result is returned. The model provides a sentiment description such as “positive,” “neutral,” or “negative.”
Breaking Down the Code
- SentimentAnalysisModel(): This is the pre-trained sentiment analysis model that Apple provides. This model is capable of determining the overall tone of a piece of text.
- analyze(text:completion:): This is the method of the model that analyzes the provided text. The result is handled through a completion block (
completion) that returns either a success or failure result. - sentimentDescription: This property provides a human-readable description of the sentiment, such as “Positive,” “Negative,” or “Neutral.”
Step 3: Integrating the Model into the User Interface
In the previous example, we’ve already shown how to use the Foundation Models framework in a SwiftUI view. However, you may want to create a more advanced example, where the user can enter text and get live sentiment analysis. Here’s how you can do that:
struct ContentView: View {
@State private var inputText: String = ""
@State private var sentiment: String = ""
var body: some View {
VStack {
TextField("Enter something to analyze...", text: $inputText)
.padding()
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: analyzeSentiment) {
Text("Analyze Sentiment")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
Text("Sentiment: \(sentiment)")
.padding()
}
.padding()
}
func analyzeSentiment() {
let model = SentimentAnalysisModel()
model.analyze(text: inputText) { result in
switch result {
case .success(let analysis):
sentiment = analysis.sentimentDescription
case .failure(let error):
sentiment = "Error: \(error.localizedDescription)"
}
}
}
}This is a basic example where the user can type text into an input field, and upon pressing the button, the model will analyze the text and return the sentiment.
Conclusion
The Foundation Models framework introduced by Apple at WWDC 2025 is a powerful tool that makes it easier to integrate artificial intelligence into your applications using pre-trained models. With its integration with SwiftUI and Xcode, you can start using state-of-the-art natural language processing models with ease, without needing to be an expert in machine learning.
In this tutorial, we covered how to integrate a sentiment analysis model into a SwiftUI app, but the Foundation Modelsframework offers much more, including models for text classification, machine translation, text generation, and more.
With this new framework, Apple opens up a world of possibilities for building smarter, more useful applications that are optimized for Apple devices, all with a learning curve that is accessible to any developer.
If you have any questions about this article, please contact me and I will be happy to help you 🙂. You can contact me on my X profile or on my Instagram profile.