Integrates and profiles Core ML models for on-device inference. Use for mlmodel/mlpackage loading, generated or feature-provider predictions, compute-unit selection, MLTensor, Vision integration, MLComputePlan, model pipelines, deployment, or performance analysis.
88%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Load, configure, and run Core ML models in iOS apps. Covers Swift model loading, synchronous/async inference, batch prediction, MLTensor, profiling, and memory management.
Scope boundary: Python-side model conversion, quantization, and pruning belong in
apple-on-device-ai. This skill owns Swift-side integration only.
.mlmodel or .mlpackage to the target; Xcode generates typed input/output classes.try await MLModel.load(contentsOf: url, configuration: config).MLModel.compileModel(at: url). Cache the resulting .mlmodelc URL in Application Support; recompiling on every launch is an error.import CoreML
let config = MLModelConfiguration()
config.computeUnits = .all
// Typed model initialization
let classifier = try MyImageClassifier(configuration: config)
// Dynamic async loading
let model = try await MLModel.load(contentsOf: modelURL, configuration: config)MLModelConfiguration controls compute dispatch:
| Value | Hardware Target | Best For |
|---|---|---|
.all | CPU + GPU + Neural Engine | Default. Best overall performance. |
.cpuAndNeuralEngine | CPU + Neural Engine | Energy efficiency, keeping GPU free for rendering. |
.cpuAndGPU | CPU + GPU | Models with operations unsupported by Neural Engine. |
.cpuOnly | CPU only | Deterministic tests, profiling baseline, background tasks. |
MLModel.prediction(...) is synchronous. Keep model loading asynchronous, then dispatch synchronous predictions from an actor or background task without adding await to prediction().
// 1. Typed prediction
let input = MyImageClassifierInput(image: pixelBuffer)
let output = try classifier.prediction(input: input)
// 2. Dynamic feature provider
let features = try MLDictionaryFeatureProvider(dictionary: ["image": MLFeatureValue(pixelBuffer: pixelBuffer)])
let dynamicOutput = try model.prediction(from: features)
// 3. Batch prediction (better throughput)
let batch = try MLArrayBatchProvider(array: featureArray)
let batchResults = try model.predictions(fromBatch: batch)
// 4. Stateful prediction (iOS 18+ for sequences/LLMs)
let state = model.makeState()
let stateOutput = try model.prediction(from: features, using: state)Predictions sharing the same MLState must be serialized; allocate independent MLState instances for concurrent streams.
MLTensor provides Swift-native multidimensional tensor math with lazy evaluation:
let tensor = MLTensor([1.0, 2.0, 3.0, 4.0]).reshaped(to: [2, 2])
let softmax = tensor.softmax(alongAxis: -1)
// Materialize asynchronously
let shapedArray = await softmax.shapedArray(of: Float.self)
let multiArray = try MLMultiArray(shapedArray)Prefer Vision pipelines to automatically handle image orientation, resizing, and pixel buffer formatting:
CoreMLRequest with Swift async/await concurrency.VNCoreMLModel(for: model) with VNCoreMLRequest and VNImageRequestHandler.try await MLComputePlan.load(contentsOf: url, configuration: config).actor, unload on memory pressure or background transitions, and share instances rather than reloading per request.MLModel.load(contentsOf:configuration:) asynchronously..compileModel(at:) outputs to Application Support.MLState instance is not thread-safe for concurrent calls. Serialize predictions or create separate states.CoreMLRequest instead.computeUnits chosen based on profiling and thermal constraintspredictions(fromBatch:)) used for multi-sample throughputCoreMLRequest) utilized for image inputsMLComputePlan inspected on iOS 17.4+ to verify Neural Engine offloadapple-on-device-aithienqo/ios-skills
6bf8b62
Canonical home
since May 23, 2026
Also appears in
on Sep 6, 2026
since May 22, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.