← All courses

EDGE FDE

Intermediate

MLX Swift in production

Keep on-device Swift inference stable across app lifecycle and newer model families.

Register a custom MLX model architecture in Swift, load weights safely, and gate inference on scenePhase so Metal is not used while backgrounded.

A newer family such as Gemma 4 loads because you registered its model_type. Generation stops when the scene leaves the foreground, so Metal does not die mid-session.

What you'll learn

Lessons

  1. Why Xcode is not production
  2. Set up Xcode and MLX Swift
  3. Register a custom architecture
  4. Gate inference on scenePhase
  5. Production checklist

Key concepts

Takeaways

Agent briefs

Core AI vs Core ML vs MLX · Route work to the right Apple model · Stream tokens and measure speed · PyTorch to Core AI in Xcode · The agent harness (and how to improve it)