blog
Ottorino Bruni  

Getting Started with Apple Foundation Models for Local AI in SwiftUI

Introduction

With the release of iOS 18, iPadOS 18, and macOS Sequoia, Apple introduced Foundation Models, a new framework that brings on-device generative AI directly into your apps. These models are part of Apple Intelligence, designed to perform natural language tasks like summarization, text understanding, classification, and creative writing all processed locally on the user’s device.

Unlike cloud-based solutions, Foundation Models run entirely within the Apple ecosystem using the SystemLanguageModel API, ensuring privacy, low latency, and deep integration with Swift. The framework allows you to build intelligent features that work even offline, powered by the Neural Engine and optimized for M-series and A17 devices.

In this article, you’ll learn what Apple Foundation Models are, how to verify model availability, and how to use them in a simple SwiftUI app. We’ll explore the core capabilities, token limits, and supported languages so you can start building your own local AI experiences right away.

In a previous post, I explored how to integrate AI in the .NET ecosystem using Microsoft.Extensions.AI.

Apple Foundation Model Hero

The Rise of Local AI Models

Over the past year, on-device and local AI models have become increasingly accessible, especially for businesses and developers building software that needs to run securely on-premise or offline.
Instead of sending data to cloud-based services, these models perform inference directly on the user’s device ensuring data privacy, lower latency, and predictable costs.

The growing trend toward local AI is driven by several key advantages:

  • Data security: Sensitive or proprietary information never leaves the device.
  • Cost efficiency: No recurring API costs for model usage.
  • Availability: Works even without an internet connection.
  • Performance: Optimized for modern CPUs, GPUs, and NPUs.

A variety of local large language models (LLMs) are now available, each with different strengths and hardware requirements:

  • Llama 3 by Meta, open and versatile, widely used for fine-tuned assistants.
  • Mistral, compact, efficient, and ideal for edge and mobile devices.
  • Gemma by Google, lightweight, fine-tuned for text generation and summarization.
  • Phi 3 by Microsoft, small but highly capable in reasoning and summarization tasks.

These models can be deployed using frameworks like Ollama, LM Studio, or Transformers, allowing developers to run AI locally on desktops, servers, or even mobile devices.
With the introduction of Apple Foundation Models, this concept is now deeply integrated into the Apple ecosystem giving developers native APIs to build intelligent apps that run privately and efficiently on Apple hardware.

What Are Apple Foundation Models

Apple Foundation Models are a new class of large language models integrated directly into iOS, iPadOS, and macOS as part of the FoundationModels framework.
They provide developers with access to the same underlying intelligence that powers Apple Intelligence, enabling features like summarization, entity extraction, classification, and creative text generation all executed securely on the device.

These models are optimized for Apple silicon, leveraging the Neural Engine for fast and energy-efficient inference. The current system language model is approximately 1.6 GB in size and supports a context window of around 4,096 tokens, which defines the total amount of text (prompts, instructions, and responses) that can fit into a single session.

Since all processing happens locally, no data leaves the device, guaranteeing full user privacy. Availability depends on both the hardware (A17 or M-series chips) and whether Apple Intelligence is enabled in Settings. Once active, the model automatically downloads and becomes accessible via SystemLanguageModel.default.

This integration makes it possible to embed generative AI features directly into your Swift and SwiftUI projects without any external dependencies or API keys a completely new approach to building intelligent apps within the Apple ecosystem.

Apple Foundation Model

When and Where Apple Intelligence Is Available

Before using the Foundation Models framework, it’s important to understand that on-device AI capabilities depend on Apple Intelligence availability.
The system language model isn’t always ready out of the box it requires both supported hardware and user activation.

Requirements (updated for iOS 26 / macOS 26)

According to the latest Apple documentation, Apple Intelligence is now widely available with iOS 26, iPadOS 26, macOS 26, and watchOS 26 on compatible devices.

To use Foundation Models and Apple Intelligence features, make sure that:

  • The device runs iOS 26, iPadOS 26, or macOS 26 (or later).
  • The hardware includes an A17 Pro, M1, or newer chip with a built-in Neural Engine.
  • Apple Intelligence is turned on in Settings → General → Apple Intelligence.
  • The on-device model (around 1.6 GB) may take a few minutes to download after activation.

Supported Languages and Regions

Apple Intelligence features are now available in most regions and support the following languages:
English, French, German, Italian, Portuguese (Brazil), Spanish, Chinese (Simplified), Japanese, and Korean.

With visionOS 26, many Apple Intelligence features are also available on Apple Vision Pro in:
English, French, German, Italian, Chinese (Simplified), Japanese, Korean, and Spanish.

Apple has announced upcoming support for eight new languages and locales:
Chinese (Traditional), Danish, Dutch, Norwegian, Swedish, Portuguese (Portugal), Vietnamese, and Turkish.

If Apple Intelligence isn’t available or not yet initialized, your app will detect the model as .unavailable.
Always verify the model’s status with SystemLanguageModel.default.availability and provide a fallback experience if the model isn’t ready.

Understanding Model Capabilities

The on-device foundation model supports a range of language understanding and generation tasks, such as summarizing text, extracting entities, classifying content, or composing short creative responses all processed locally without network access.
It’s ideal for features like summaries, text improvement, tagging, and simple conversational replies within your app.

However, the model isn’t designed for everything. Tasks involving math, code generation, or complex logical reasoning aren’t supported and may produce unreliable results.

By focusing on concise and text-based interactions, you can get the best performance and reliability from Apple’s on-device AI.

Checking Model Availability

Before you start generating text or analyzing input, your app should always verify that the on-device model is ready to use.
The Foundation Models framework provides a simple way to check this through the SystemLanguageModel.default property, which reflects whether Apple Intelligence is available and active on the current device.

The model’s availability depends on several factors:

  • The device must support Apple Intelligence (A17 Pro, M1, or later).
  • The feature must be enabled in Settings.
  • The on-device model must have finished downloading.
  • The model may still report .modelNotReady while it’s initializing in the background.

Use the availability property to detect these conditions and provide a clear user experience in your SwiftUI app.

Example

import SwiftUI
import FoundationModels

struct ModelAvailabilityView: View {
    private var model = SystemLanguageModel.default

    var body: some View {
        VStack(spacing: 12) {
            switch model.availability {
            case .available:
                Text("Apple Intelligence is available and ready to use.")
            case .unavailable(.deviceNotEligible):
                Text("This device doesn’t support Apple Intelligence.")
            case .unavailable(.appleIntelligenceNotEnabled):
                Text("Please enable Apple Intelligence in Settings to continue.")
            case .unavailable(.modelNotReady):
                Text("The on-device model is still downloading or initializing.")
            case .unavailable(let other):
                Text("Model unavailable: \(other.localizedDescription)")
            }
        }
        .padding()
    }
}

This simple view checks the model’s readiness and helps you design an appropriate fallback UI if Apple Intelligence is disabled or unavailable.
In production apps, you can combine this logic with an onboarding or settings screen to guide users through enabling Apple Intelligence before using your AI-powered features.

Creating a Language Model Session

Once you confirm that the system language model is available, the next step is to create a session that manages your interaction with the model.
In the Foundation Models framework, a LanguageModelSession represents a conversation context it holds the instructions you give to the model and the prompts it responds to.

Each session can handle a single request at a time, but you can reuse it to maintain context across multiple turns.
For short, single-turn interactions, create a new session for each request.

You can initialize a session with instructions, which define how the model should behave and respond.
Instructions act as a kind of “system prompt” that guides tone, style, and safety boundaries.

Example

import FoundationModels

// Define high-level instructions that apply to all prompts in this session.
let instructions = """
You are a helpful assistant that responds clearly and concisely.
Keep answers short and easy to understand.
"""

// Create a new session with the system language model.
let session = LanguageModelSession(instructions: instructions)

You can then send a prompt to the session using respond(to:):

let prompt = "Summarize what SwiftUI is in three sentences."
let response = try await session.respond(to: prompt)

print(response)

For more advanced control, the framework lets you customize generation parameters using GenerationOptions.
For example, you can adjust the creativity level with temperature or set a limit on token output:

let options = GenerationOptions(temperature: 1.0, maxTokens: 200)
let refinedResponse = try await session.respond(to: prompt, options: options)

A single LanguageModelSession can only process one request at a time.
If you call respond(to:) again before the previous response finishes, the framework throws a runtime error.
You can check the property isResponding to ensure the model has finished generating before sending a new prompt.

Example: Building a Simple Local AI View in SwiftUI

Disclaimer: This example is purely for educational purposes. There are better ways to write code and applications that can optimize this example. Use this as a starting point for learning, but always strive to follow best practices and improve your implementation.

Building a Simple Local AI View in SwiftUI Video

Prerequisites

Before starting, make sure you have the following installed:

  • Xcode 16 or later (required for iOS 18, iPadOS 18, or macOS Sequoia).
  • A supported device with Apple Intelligence enabled in Settings → General → Apple Intelligence
  • FoundationModels framework available in your SDK (part of Xcode 16).

Step 1 – Create a New SwiftUI Project

Open Xcode, create a new App project, and select SwiftUI App as the template.
Name it for example LocalAIPlayground.

Example: Basic Code

Step 2 – Import the Framework and Set Up the View

Add the FoundationModels import at the top of your file.
Then create a simple SwiftUI view that interacts with the on-device foundation model.

import SwiftUI
import FoundationModels

struct LocalAIView: View {
    @State private var prompt = ""
    @State private var response = ""
    private let model = SystemLanguageModel.default

    var body: some View {
        VStack(spacing: 16) {
            Text("Local AI Assistant")
                .font(.title3)
                .bold()

            TextField("Enter your prompt...", text: $prompt)
                .textFieldStyle(.roundedBorder)
                .padding(.horizontal)

            Button("Generate Response") {
                Task {
                    guard model.availability == .available else {
                        response = "Apple Intelligence is not available on this device."
                        return
                    }

                    let session = LanguageModelSession(
                        instructions: "You are a concise and friendly assistant."
                    )

                    do {
                        let output = try await session.respond(to: prompt)
                        response = output.content
                    } catch {
                        response = "Error: \(error.localizedDescription)"
                    }
                }
            }
            .buttonStyle(.borderedProminent)
            .padding(.horizontal)

            ScrollView {
                Text(response)
                    .padding()
                    .frame(maxWidth: .infinity, alignment: .leading)
            }
            .frame(maxHeight: 300)
            .background(Color(.secondarySystemBackground))
            .cornerRadius(12)
            .padding(.horizontal)
        }
        .padding()
    }
}
Example: Building a Simple Local AI View in SwiftUI

Step 3 – Run the App

Build and run the app on a supported device.
If Apple Intelligence is active, you’ll be able to type any natural language prompt (like “Summarize SwiftUI in two sentences”) and get a local AI-generated response instantly.
If the model isn’t yet available, the app will display a helpful fallback message instead.

Run Local AI View

Step 4 – Extend and Experiment

From here, you can:

  • Add temperature and token controls using GenerationOptions.
  • Reuse a session for multi-turn conversations.
  • Create task-specific instructions, like summarizing or generating tags.

This example demonstrates how easy it is to bring on-device AI into your SwiftUI projects using Apple’s Foundation Models framework without relying on external APIs or network connections.

Language and Locale Support

Overview

The on-device foundation model is multilingual, which means it can understand and generate content in multiple languages supported by Apple Intelligence.
Unlike traditional language models that require separate downloads or configurations, the same model dynamically adapts to the language of the user or the language you specify in your app’s instructions.

To create a seamless user experience, your app should:

  • Detect the user’s preferred language.
  • Verify that it’s supported by the current model.
  • Gracefully handle cases where the language isn’t yet available.

Checking Language Support in Your App

Use the supportsLocale(_:) method on SystemLanguageModel.default to check whether Apple Intelligence supports the current language settings:

import FoundationModels

if SystemLanguageModel.default.supportsLocale() {
    print("Current language is supported by Apple Intelligence.")
} else {
    print("Current language is not supported yet.")
}

Retrieve the List of Supported Languages

For advanced use cases (for example, showing a language selector), you can query all supported languages using the supportedLanguages property

for language in SystemLanguageModel.default.supportedLanguages {
    print(language.identifier)
}

Prompting the Model in a Specific Language

When you provide prompts or instructions, you can explicitly set the desired language by writing your text in that language.
For example:

let session = LanguageModelSession(
    instructions: "Responde en español de forma breve y clara."
)

let prompt = "¿Qué es SwiftUI?"
let response = try await session.respond(to: prompt)
print(response)

Limitations and Best Practices

Apple Foundation Models offer powerful on-device AI but come with key constraints to consider.
Each LanguageModelSession supports a context window of ~4,096 tokens, so keep prompts short and focused.
The model can’t perform math, code generation, or complex reasoning, and may be unavailable while Apple Intelligence is disabled or still downloading.
To ensure good performance, limit maxTokens, use concise prompts, and profile with Xcode Instruments.
All processing stays private on device, but always validate inputs and provide a fallback UI when the model isn’t ready.

Design with these limits in mind to create stable, fast, and privacy-respecting AI experiences on Apple platforms.

Conclusion

Having access to a local AI model can be extremely valuable when you want to integrate intelligent behavior into your apps without relying on third-party APIs or an internet connection.
Apple Foundation Models make it possible to summarize content, refine user input or enhance app responses entirely on device, with full privacy and zero network dependency.

While the current capabilities are still limited to text-based tasks, this framework marks an important first step. It’s a powerful foundation for experimenting, prototyping and learning how to bring AI features directly into your Swift and SwiftUI projects locally, privately and efficiently.

If you think your friends or network would find this article useful, please consider sharing it with them. Your support is greatly appreciated.

Thanks for reading!

Discover CodeSwissKnife Bar, your all-in-one, offline Developer Tools from Your Menu Bar

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.