Environment setup
Use Xcode 27 (the SDK version this site uses for iOS 27 and macOS 27) on an Apple silicon Mac. Create an iOS or macOS SwiftUI App target. Set the deployment target to iOS 27 or macOS 27 to match the rest of the Edge FDE catalog. Install the Metal Toolchain from Xcode Settings > Components if Xcode asks for it.
xcode-select --install
xcodebuild -version
# In Xcode: File > New > Project > App, Interface: SwiftUI
# Xcode Settings > Components > install Metal Toolchain if prompted.
Add the packages from File > Add Package Dependencies. Pin a current release. Then open the README on GitHub and confirm the product names for the tag you pinned. Names move. Do not copy a version from memory.
# Package URLs to paste in Xcode
# https://github.com/ml-explore/mlx-swift
# https://github.com/ml-explore/mlx-swift-lm
# Confirm the latest tagged release on each repo before you pin.
In the app target, add the products you will import. A typical LLM app needs MLX from mlx-swift, plus MLXLLM and MLXLMCommon from mlx-swift-lm. Many apps also add MLXHuggingFace for Hub download and tokenizer wiring. If the README for your tag lists extra packages such as swift-huggingface, add those too. The sketch below is a Package.swift shape, not a frozen version pin.
// Sketch. Confirm products and version pins in the
// mlx-swift-lm README for the tag you resolved.
dependencies: [
.package(url: "https://github.com/ml-explore/mlx-swift-lm", from: "3.31.3"),
],
targets: [
.target(
name: "YourAppTarget",
dependencies: [
.product(name: "MLXLLM", package: "mlx-swift-lm"),
.product(name: "MLXLMCommon", package: "mlx-swift-lm"),
.product(name: "MLXHuggingFace", package: "mlx-swift-lm"),
]
),
]
Build the empty app once before you download weights. If the packages fail to resolve, stop and fix the pin. Do not debug generate on a broken graph.
Mac, Simulator, and device
Be honest about where Metal actually runs.
- Apple silicon Mac. A macOS target can run MLX on the GPU. This is the fastest way to test load and generate.
- iOS Simulator. Use it to compile SwiftUI and to click through scene changes. Do not treat Simulator GPU as the phone. MLX Metal on Simulator is not the production path.
- Real iPhone or iPad. This is the iOS Metal path. Background the app here when you test lesson 04. Memory and jetsam only show up on device.
PyTorch to Core AI in Xcode is the other Xcode path on this site: train, convert, ship a .aimodel. Stay on this course when the runtime is MLX Swift, not Core AI. Core AI vs Core ML vs MLX helps you say that out loud to a stakeholder.
Next, register the architecture so a family such as Gemma 4 can load.
Key concepts
- Xcode 27 on an Apple silicon Mac. iOS 27 or macOS 27 SwiftUI app.
- Add mlx-swift and mlx-swift-lm. Confirm product names on the tag you pinned.
- Mac can run the GPU. Simulator is compile and UI. A real device is the iOS Metal path.
- Build the empty app before you download weights or write generate.
Takeaways
- Pin current packages and re-read the README. Do not invent product names.
- Use Simulator for UI. Use a Mac or a device for Metal.
- You now have an environment. The first runnable load is the next lesson.