Apple Foundation Models
Learn how to build intelligent SwiftUI applications using Apple's Foundation Models framework, guided generation, prompt engineering, and on-device AI technologies. By Bill Morefield.
Who is this for?
This book is for Swift developers who are familiar with writing SwiftUI apps and who want to build intelligent, AI-powered applications using Apple’s new Foundation Models framework and on-device machine learning technologies.
Covered concepts
- Understanding LLMs
- Streaming Model Responses
- Managing Model Sessions
- Prompt Engineering
- AI Safety and Limitations
- Guided Generation
- Dynamic Schemas
- Integrating External Tools
- Building Real AI Apps
Apple Foundation Models is a practical guide to building intelligent, on-device AI applications using Apple’s new Foundation Models framework. Designed for Swift developers, this book introduces the fundamentals of large language models before guiding you through real-world implementations using Apple’s on-device AI technologies.
Throughout the book, you’ll learn how to...
moreBefore You Begin
This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.
Section I: Apple Foundation Models
This section provides a comprehensive introduction to Apple’s Foundation Models framework and its integration into SwiftUI applications. It begins with a practical overview of Large Language Models (LLMs), introducing the terminology, capabilities, and limitations that developers must understand before working with on-device intelligence. From there, it guides you through building conversational SwiftUI applications powered by Foundation Models, demonstrating how to interact with models in real time and create responsive, user-friendly experiences.
The section then explores the mechanics of model sessions, including transcript management, persistence, and strategies for handling limited context windows. It examines how developers can maintain meaningful conversations while working within the constraints of on-device models. Alongside these practical concerns, it presents an in-depth discussion of prompt engineering and safety, covering techniques for crafting reliable prompts while addressing challenges such as hallucinations, inconsistent output, and responsible AI usage.
Building on these foundations, the section introduces Guided Generation, one of the framework’s most powerful features for producing structured and strongly typed data. It demonstrates how to define schemas using Swift macros, enforce constraints on generated content, and dynamically construct data structures at runtime when compile-time definitions are unavailable. It further explores the integration of external tools and data sources, showing how models can be extended beyond their static training data to provide more contextual and useful responses.
Finally, the section brings these concepts together through the development of a practical on-device AI application. Using modern machine learning and Foundation Models, you will build an app capable of capturing audio, converting speech to text, summarizing content, and extracting meaningful information from user input. Each chapter provides both conceptual understanding and hands-on implementation, ensuring you develop a strong and practical foundation for building intelligent SwiftUI applications with Apple’s new Foundation Models framework.