Core AI is a new iOS 27 framework that lets developers bring their own .aimodel files (e.g. open-source LLMs, vision-transformers) on-device and run them through the familiar FoundationModels session API β no server, no per-token cost, no data leaving the device.
β’ Bring any compatible open-source model (Qwen, SAM 3, etc.) into your app using the same LanguageModelSession API as Apple Intelligence, with structured output and streaming built in
β’ User data never leaves the device β models run entirely locally, enabling privacy-sensitive use cases that cloud APIs can't support
β’ Task-specific models under 1B parameters keep storage and memory manageable, and the coreai-models Swift package abstracts tensor pre/post-processing so you write clean Swift code instead of wrangling shapes
Loads a local Qwen .aimodel file via CoreAILanguageModel, then uses a standard FoundationModels LanguageModelSession with a @Generable struct to generate a Mandarin vocabulary card from an English label β all on-device.
import SwiftUI
import FoundationModels
import CoreAILM
// 1. Describe the structured output with @Generable
@Generable
struct VocabCard {
@Guide(description: "The word in Mandarin Chinese (simplified characters)")
var mandarinWord: String
@Guide(description: "Pinyin romanisation of the Mandarin word")
var pinyin: String
@Guide(description: "A natural example sentence in Mandarin using the word")
var exampleSentence: String
@Guide(description: "English translation of the example sentence")
var exampleTranslation: String
}
// 2. Actor that owns the model session
actor VocabCardActor {
private var session: LanguageModelSession?
func prepare(modelURL: URL) throws {
// Load the .aimodel bundle β tokeniser, engine, assets all wired up automatically
let customModel = try CoreAILanguageModel(contentsOf: modelURL)
// Pass it into a standard FoundationModels session
session = LanguageModelSession(model: customModel)
}
func generateCard(for englishLabel: String) async throws -> VocabCard {
guard let session else { throw VocabError.notReady }
let prompt = "Generate a Mandarin Chinese vocabulary card for the English word: \(englishLabel)"
let response = try await session.respond(
to: prompt,
generating: VocabCard.self
)
return response.value
}
enum VocabError: Error { case notReady }
}
// 3. SwiftUI view wiring it together
struct VocabCardView: View {
let englishLabel: String
@State private var card: VocabCard?
@State private var isLoading = false
private let actor = VocabCardActor()
var body: some View {
VStack(spacing: 16) {
if let card {
Text(card.mandarinWord).font(.largeTitle)
Text(card.pinyin).foregroundStyle(.secondary)
Divider()
Text(card.exampleSentence).italic()
Text(card.exampleTranslation).foregroundStyle(.secondary)
} else if isLoading {
ProgressView("Generating cardβ¦")
} else {
Button("Generate Card for \(englishLabel)") {
Task { await generate() }
}
.buttonStyle(.borderedProminent)
}
}
.padding()
}
private func generate() async {
isLoading = true
defer { isLoading = false }
do {
// modelURL points to the exported Qwen .aimodel bundle in the app container
let modelURL = Bundle.main.url(forResource: "Qwen", withExtension: "aimodel")!
try await actor.prepare(modelURL: modelURL)
card = try await actor.generateCard(for: englishLabel)
} catch {
print("Card generation failed: \(error)")
}
}
}
#Preview {
VocabCardView(englishLabel: "Hummingbird")
}Model specialization only happens once (result is cached), but the first load can freeze the UI if triggered inline β always move it to a dedicated first-run or background step. Models must be exported to the .aimodel format via the Core AI PyTorch extensions or the coreai-models repo conversion scripts before they can be loaded. The CoreAILanguageModel initialiser is part of the coreai-models Swift package (not a first-party framework), so you must add that package dependency separately.
Requires Apple Silicon or A-series device capable of Neural Engine inference; model specialization (first-run compilation) can take significant time on first load and should be triggered outside the interactive flow; total model footprint for two sub-1B models exceeds 1 GB so use Background Assets for on-demand download
More iOS 27 APIs land every week.
Get notified when new capabilities are published β no noise, just signal.