Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Coreml

ASecurity

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.

3 stars
0 votes
0 copies
0 views
Added 9/28/2026
developmentpythonswiftperformancedocumentation

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add thiennc-tesoglobal/ios-skills --skill coreml --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coreml?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Coreml
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/thiennc-tesoglobal-coreml/badge)](https://www.skillsdirectory.com/skills/thiennc-tesoglobal-coreml)

More formats (shields.io, HTML) on the badges page.

Files
SKILL.md
---
name: coreml
description: "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."
---

# Core ML Swift Integration

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.

## Contents

- [Loading Models](#loading-models)
- [Model Configuration](#model-configuration)
- [Making Predictions](#making-predictions)
- [MLTensor (iOS 18+)](#mltensor-ios-18)
- [Vision Integration](#vision-integration)
- [Performance & Memory](#performance--memory)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

## Loading Models

- **Auto-Generated Class**: Add `.mlmodel` or `.mlpackage` to the target; Xcode generates typed input/output classes.
- **Async Loading (iOS 15+)**: Avoid blocking the main thread: `try await MLModel.load(contentsOf: url, configuration: config)`.
- **Runtime Compilation (iOS 16+)**: Compile downloaded packages with `MLModel.compileModel(at: url)`. Cache the resulting `.mlmodelc` URL in Application Support; recompiling on every launch is an error.

```swift
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)
```

## Model Configuration

`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. |

## Making Predictions

`MLModel.prediction(...)` is synchronous. Keep model loading asynchronous, then dispatch synchronous predictions from an actor or background task without adding `await` to `prediction()`.

```swift
// 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 (iOS 18+)

`MLTensor` provides Swift-native multidimensional tensor math with lazy evaluation:

```swift
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)
```

## Vision Integration

Prefer Vision pipelines to automatically handle image orientation, resizing, and pixel buffer formatting:

- **iOS 18+**: Use `CoreMLRequest` with Swift async/await concurrency.
- **Legacy (iOS 11-17)**: Use `VNCoreMLModel(for: model)` with `VNCoreMLRequest` and `VNImageRequestHandler`.

## Performance & Memory

- **MLComputePlan (iOS 17.4+)**: Inspect execution dispatch per operation prior to inference: `try await MLComputePlan.load(contentsOf: url, configuration: config)`.
- **Instruments**: Profile with the Core ML template outside Xcode debugger to measure latency and ANE offload.
- **Lifecycle & Cache**: Manage models inside an `actor`, unload on memory pressure or background transitions, and share instances rather than reloading per request.

## Common Mistakes

- **Loading models on the main thread**: Blocks UI rendering. Always use `MLModel.load(contentsOf:configuration:)` asynchronously.
- **Recreating MLModel instances per prediction**: Model compilation and weight initialization are expensive. Cache and reuse model instances in an actor.
- **Recompiling models on every launch**: Always persist runtime `.compileModel(at:)` outputs to Application Support.
- **Concurrent inference with shared MLState**: An `MLState` instance is not thread-safe for concurrent calls. Serialize predictions or create separate states.
- **Preprocessing images manually**: Manual cropping and scaling causes color space and orientation bugs. Use Vision's `CoreMLRequest` instead.

## Review Checklist

- [ ] Model loaded asynchronously without stalling the main thread
- [ ] Runtime-compiled models persisted and reused across app launches
- [ ] Appropriate `computeUnits` chosen based on profiling and thermal constraints
- [ ] Single model instance shared via actor rather than re-instantiated
- [ ] Batch predictions (`predictions(fromBatch:)`) used for multi-sample throughput
- [ ] Vision framework (`CoreMLRequest`) utilized for image inputs
- [ ] `MLComputePlan` inspected on iOS 17.4+ to verify Neural Engine offload
- [ ] Memory warnings handled by releasing cached model instances

## References

- Actor-based caching, MLBatchProvider, and MLComputePlan recipes: [references/coreml-swift-integration.md](references/coreml-swift-integration.md)
- Model quantization and coremltools conversion: covered in `apple-on-device-ai`
- [Core ML Framework](https://sosumi.ai/documentation/coreml)
- [MLModel](https://sosumi.ai/documentation/coreml/mlmodel)
- [MLTensor](https://sosumi.ai/documentation/coreml/mltensor)
- [MLComputePlan](https://sosumi.ai/documentation/coreml/mlcomputeplan-1w21n)
- [Background Assets](https://sosumi.ai/documentation/backgroundassets)

Attribution

thiennc-tesoglobalthiennc-tesoglobal
View sourceMore from thiennc-tesoglobal →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284972 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →