Core ML: On-Device Machine Learning for Apple Apps

Core ML runs pre-trained machine learning models directly on Apple devices, enabling fast, private, and offline AI. It's used for features like real-time image recognition or text analysis. The footgun: Core ML only runs models; it doesn't train them.
WHY IT EXISTS Running machine learning models on a server introduces latency, requires an internet connection, and raises privacy concerns about user data. Core ML was created to solve these problems by allowing developers to run models directly on a user's iPhone, iPad, or Mac, enabling fast, private, and offline AI features.
THE MENTAL MODEL Think of Core ML as a highly optimized "model runner" for Apple's ecosystem. It doesn't know how to train a model. Instead, you provide a pre-trained model, and Core ML handles the complex job of executing it efficiently on the device's hardware, abstracting away the differences between the CPU, GPU, and the specialized Apple Neural Engine (ANE).
HOW IT WORKS The process involves two phases. First, an offline phase where you train a model using a standard framework like TensorFlow or PyTorch. You then use Apple's coremltools Python library to convert that model into the .mlmodel or .mlpackage format. Second, an on-device phase where you bundle this file in your app. Your Swift code loads the model, provides it with an input (like an image or text), and receives a prediction. Core ML automatically manages the computation, dispatching it to the best available hardware for performance and power efficiency.
WHEN TO USE IT Use Core ML for features that need real-time, low-latency predictions and must work offline. It's ideal for interactive experiences like live camera filters, object detection, or transcribing audio as it's spoken. It's also the best choice when user data is sensitive and should not leave the device, such as analyzing text in a private messaging app.
WHEN NOT TO USE IT Core ML is not for training models from scratch on-device. If your model is too large to be bundled with an app (multiple gigabytes) or requires computational power beyond a mobile device, a server-based approach is necessary. Similarly, if the model needs to be updated for all users instantly and frequently, deploying updates via a server is more practical than shipping a new app version.
ONE CANONICAL EXAMPLE A classic use case is an image classification app. A developer trains a model to recognize different species of flowers. They convert this model to the .mlmodel format and include it in their iOS app. When a user points their camera at a flower, the app feeds the live video frame to the Core ML model. The model processes the image and returns a prediction, like "Daisy" with 95% confidence, all in a fraction of a second and without an internet connection.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.