Back to Swift Reference
🧠 Apple IntelligenceIntermediateiOS 26+ · Apple Intelligence devices

Foundation Models Framework

Run Apple’s on-device language model from Swift — private, offline and free of API costs.

LanguageModelSession gives you a conversation with the on-device model. Instructions set the behavior; each respond(to:) call adds to the session transcript.

Always check SystemLanguageModel.default.availability — the model is unavailable on unsupported devices or when Apple Intelligence is turned off.

foundation-models.swift
1import FoundationModels
2
3@MainActor
4@Observable
5final class SummaryModel {
6    var output = ""
7    private let session = LanguageModelSession(
8        instructions: "You summarize journal entries in two friendly sentences."
9    )
10
11    func summarize(_ text: String) async {
12        guard case .available = SystemLanguageModel.default.availability else {
13            output = "Apple Intelligence is not available on this device."
14            return
15        }
16        do {
17            let response = try await session.respond(to: text)
18            output = response.content
19        } catch {
20            output = "Could not summarize: \(error.localizedDescription)"
21        }
22    }
23}

Common pitfalls

  • The on-device model has a limited context window — summarize or trim long inputs.
  • Design a graceful fallback UI for devices without Apple Intelligence.

Still unclear? Ask BeeAI about Foundation Models Framework.

Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.

Ask BeeAI

Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.

See Pro Plans