Community-maintained Agent Skills for complete Swift and Apple-platform app delivery.
72
90%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Medium
Suggest reviewing before use
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-ai.tessl-plugin
skills
accessorysetupkit
references
activitykit
adattributionkit
references
alarmkit
references
app-clips
app-intents
app-store-optimization
app-store-review
apple-on-device-ai
appmigrationkit
audioaccessorykit
references
authentication
references
avfoundation-audio
references
avkit
background-processing
references
browserenginekit
callkit
references
carplay
cloudkit
contacts-framework
references
core-bluetooth
references
core-data
core-haptics
references
core-motion
references
core-nfc
references
coreml
references
cryptokit
cryptotokenkit
debugging-instruments
device-integrity
references
energykit
references
eventkit
family-controls
references
financekit
focus-engine
gamekit
git-branching-workflow
references
healthkit
references
homekit
references
ios-accessibility
ios-app-workflow
references
ios-ettrace-performance
ios-localization
ios-memgraph-analysis
ios-networking
ios-simulator
references
metrickit
references
musickit
references
natural-language
paperkit
references
passkit
references
pdfkit
pencilkit
references
permissionkit
references
photokit
push-notifications
quicklook
references
realitykit
references
relevancekit
references
scenekit
sensorkit
shazamkit
references
speech-recognition
references
spritekit
storekit
swift-api-design-guidelines
swift-architecture
references
swift-charts
swift-codable
references
swift-code-review
swift-concurrency
swift-formatstyle
references
swift-language
swift-security
references
swift-testing
swiftdata
swiftlint
swiftui-animation
swiftui-gestures
references
swiftui-layout-components
swiftui-liquid-glass
references
swiftui-patterns
swiftui-performance
swiftui-responsive-layout
swiftui-uikit-interop
swiftui-webkit
tabletopkit
tipkit
vision-framework
weatherkit
references