Core AI is Apple's new on-device inference framework for iOS 27, giving developers direct access to the same high-performance ML execution engine that powers Apple Intelligence. It supports CPU, GPU, and Neural Engine across all Apple Silicon devices.
• Run your own AI/ML models entirely on-device with no server costs or per-token fees, using the same engine that powers Apple Intelligence
• A modern Swift API with memory-safe primitives (NDArray, InferenceFunction) makes integration straightforward for any model size
• Complete toolchain support — CoreAI Torch Python converter, ahead-of-time compilation, dedicated Instruments integration, and a visual tensor debugger — shortens the iterate-evaluate-ship cycle dramatically
Loads a converted .aimodel file, prepares an NDArray of float32 features, runs inference on the Neural Engine via Core AI, and reads the output logits — all on-device with no network calls.
import CoreAI
import SwiftUI
// MARK: - Core AI inference wrapper
actor DirectionPredictor {
private let inferenceFunction: InferenceFunction
// hiddenDim must match the model's fixed second dimension
let hiddenDim: Int = 32
init(modelURL: URL) throws {
let model = try AIModel(contentsOf: modelURL)
self.inferenceFunction = try model.loadMainFunction()
}
/// Predict the best direction index (0-3) from a sequence of feature vectors.
func predict(featureSequence: [[Float]]) throws -> Int {
let seqLen = featureSequence.count
// Create a 2-D NDArray [seqLen, hiddenDim] backed by float32
var inputArray = NDArray(
shape: [seqLen, hiddenDim],
dataType: .float32
)
// Fill NDArray row-by-row via a MutableView
inputArray.withMutableView { view in
for (row, features) in featureSequence.enumerated() {
for (col, value) in features.prefix(hiddenDim).enumerated() {
view[row, col] = value
}
}
}
// Run inference — dispatches to CPU/GPU/Neural Engine automatically
let outputs = try inferenceFunction.run(["features": inputArray])
guard let logitsArray = outputs["logits"] else {
throw PredictorError.missingOutput
}
// Read logits and return the index of the highest value
let logits: [Float] = logitsArray.withView { view in
(0..<4).map { view[0, $0] as Float }
}
return logits.indices.max(by: { logits[$0] < logits[$1] }) ?? 0
}
enum PredictorError: Error {
case missingOutput
}
}
// MARK: - SwiftUI demo view
struct CoreAIDemoView: View {
@State private var predictedDirection: String = "—"
@State private var isRunning = false
private let directions = ["Up", "Down", "Left", "Right"]
// In a real app, bundle the .aimodel and resolve with Bundle.main.url
private let modelURL = Bundle.main.url(
forResource: "SnakeTransformer", withExtension: "aimodel"
)!
var body: some View {
VStack(spacing: 24) {
Text("Core AI Demo")
.font(.title2.bold())
Text("Predicted direction")
.foregroundStyle(.secondary)
Text(predictedDirection)
.font(.largeTitle.bold())
.contentTransition(.numericText())
Button(isRunning ? "Running…" : "Run Inference") {
Task { await runInference() }
}
.buttonStyle(.borderedProminent)
.disabled(isRunning)
}
.padding()
}
@MainActor
func runInference() async {
isRunning = true
defer { isRunning = false }
do {
let predictor = try DirectionPredictor(modelURL: modelURL)
// Simulate 3 game-state feature vectors of length 32
let fakeSequence = (0..<3).map { _ in
(0..<32).map { _ in Float.random(in: -1...1) }
}
let index = try await predictor.predict(featureSequence: fakeSequence)
predictedDirection = directions[index]
} catch {
predictedDirection = "Error: \(error.localizedDescription)"
}
}
}
#Preview {
CoreAIDemoView()
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, allowing anyone to integrate server-based or local models (e.g. Claude, Gemini, CoreAI, MLX) using the same API as Apple's on-device system model.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence →Models must be converted from PyTorch to the .aimodel format via the coreai Python package before shipping; dynamic input shapes must be declared explicitly at export time using dynamic_shapes or they will be traced statically. States (key/value caches) require additional model authoring changes to benefit from caching. The framework is new in iOS 27 so there is no backward-compatible fallback on older OS versions.
Requires Apple Silicon; Neural Engine acceleration available on A-series and M-series chips. Model file must be converted to .aimodel format using the Core AI Torch Python package before use.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.