Foundation Models is a new Apple framework introduced in iOS 27 that provides on-device access to the Apple Intelligence language model, enabling text generation, structured output, and tool calling directly on device without network calls.
• Run powerful on-device LLM inference with zero network latency or privacy concerns — user data never leaves the device
• Generate structured Swift types directly from the model using the @Generable macro, eliminating fragile JSON parsing
• Supports streaming responses, tool calling, and stateful sessions, making it straightforward to build chat-style or agentic features
Uses Foundation Models to generate a structured travel itinerary as a typed Swift struct, demonstrating the @Generable macro and streaming text generation in a SwiftUI view.
import SwiftUI
import FoundationModels
@Generable
struct Itinerary {
@Guide(description: "The destination city and country")
var destination: String
@Guide(description: "A list of exactly 3 recommended activities")
var activities: [String]
@Guide(description: "Estimated budget in USD as an integer")
var estimatedBudget: Int
}
@MainActor
class TripPlannerViewModel: ObservableObject {
@Published var itinerary: Itinerary?
@Published var streamingText: String = ""
@Published var isLoading = false
@Published var errorMessage: String?
private let session = LanguageModelSession()
func planTrip(to destination: String) async {
guard LanguageModel.isAvailable else {
errorMessage = "Apple Intelligence is not available on this device."
return
}
isLoading = true
streamingText = ""
defer { isLoading = false }
do {
let prompt = "Create a travel itinerary for a 3-day trip to \(destination)."
let stream = session.streamResponse(to: prompt, generating: Itinerary.self)
for try await partial in stream {
self.itinerary = partial
}
} catch {
errorMessage = error.localizedDescription
}
}
}
struct TripPlannerView: View {
@StateObject private var viewModel = TripPlannerViewModel()
@State private var destination = "Kyoto, Japan"
var body: some View {
NavigationStack {
Form {
Section("Destination") {
TextField("Enter a city", text: $destination)
}
Section {
Button("Plan My Trip") {
Task { await viewModel.planTrip(to: destination) }
}
.disabled(viewModel.isLoading)
}
if let itinerary = viewModel.itinerary {
Section("Destination") {
Text(itinerary.destination)
}
Section("Activities") {
ForEach(itinerary.activities, id: \.self) { activity in
Label(activity, systemImage: "mappin.circle")
}
}
Section("Estimated Budget") {
Text("$\(itinerary.estimatedBudget) USD")
.bold()
}
}
if let error = viewModel.errorMessage {
Section { Text(error).foregroundStyle(.red) }
}
if viewModel.isLoading {
Section { ProgressView("Generating itinerary…") }
}
}
.navigationTitle("Trip Planner")
}
}
}Sessions are stateful — reuse a LanguageModelSession across turns for multi-turn conversations. The @Generable macro requires the FoundationModels import and only works on structs/classes with Codable-compatible properties. Availability must be checked at runtime via LanguageModel.isAvailable before attempting inference. Beta builds may have generation quality limitations.
Requires an Apple Intelligence-capable device (iPhone 16 or later, iPad with M-series chip); not available in all regions at launch
More iOS 27 APIs land every week.
Get notified when new capabilities are published — no noise, just signal.