💡Machine Learning on iOS
Spring 2026 | Jay Zheng
What is Machine Learning?
Normally when you write a program, you spell out every rule explicitly — "if the pixel is red, do this; if it's blue, do that." That works fine for simple logic, but it breaks down fast for complex tasks like recognizing a cat in a photo. There are too many rules to write by hand.
Machine learning flips this around. Instead of writing the rules yourself, you feed the computer a pile of data (say, thousands of labeled photos) and let an algorithm figure out the rules on its own. That process produces a model.
Core idea: Data + Algorithm -> Model
Think of the model as a black box — you don't need to know what's going on inside it. All you need to know is:
It takes some input (an image, a sentence, a number).
It produces some output (a label, a score, a prediction).
For example, in this demo app below, the input is a photo and the output is a label like "golden retriever — 94% confident."
The algorithm you choose depends on what you're trying to do. Classifying images calls for a different algorithm than predicting house prices or generating text. That's most of what machine learning research is about — figuring out which algorithms work best for which problems (you can learn more in CS 3780). For this demo, we're using a pre-trained neural network called MobileNetV2 that's already been tuned for image classification.
Machine Learning on iOS
When you hear "AI" or "ML," you probably think of something that lives in the cloud — you send a request to ChatGPT or Claude, OpenAI's or Anthropic's servers process it and you get a response back.
iOS does it differently. Apple wanted ML to run on the device itself, for a few reasons:
Privacy — your data never leave the phone.
Speed — Light weight model and instant result.
Offline — Not wifi/cellular network dependent.
No server costs — you don't pay for token.
To make this practical, Apple built a stack of frameworks:
Core ML
Runs ML models on the iPhone's chips, and Neuro Engine introduced in 2017 with A11 Bionic Chip.
Vision
High-level wrapper for image tasks (classification, face/text detection).
Natural Language
Same idea, but for text.
Create ML
An app that lets you train your own models without writing ML code.
The model file format Apple uses is .mlmodel. You drag one into your Xcode project and Xcode automatically generates a Swift class for it — that's why you can write MobileNetV2() in code below without ever defining that class yourself.
To get started, visit each explandable below
Demo has a working image classification app, you can try it and see how it works
Limitation on MobileNetV2 talks about what the model we use in the demo can not do
Training your own model with createML gives you the steps to training your own ML model that you can use in your own project.
Last updated
Was this helpful?