Apple showed how the @Generable and @Guide macros in FoundationModels simplify Swift development

Apple showed how FoundationModels can shorten the path from prompt to a ready data structure. The @Generable macro marks a Swift model as suitable for generation, while @Guide helps refine individual fields. As a result, the developer gets a stream of typed objects that can be used immediately in SwiftUI without manually parsing the model’s response. This reduces the amount of boilerplate code and makes LLM integration into the interface noticeably more practical.

AI-processed from Habr AI; edited by Hamidun News
Apple showed how the @Generable and @Guide macros in FoundationModels simplify Swift development
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Clarity — the model understands exactly what each field should contain
Key metric #2Validation — hints reduce the likelihood of incorrect or irrelevant data
Key metric #3Consistency — across multiple generations, outputs remain predictable

Apple showed how @Generable and @Guide macros in

FoundationModels simplify Swift development

Apple continues to improve its approach to integrating artificial intelligence into Swift. The latest step is the @Generable and @Guide macros, which allow developers to work with structured generation from language models in a type-safe way.

What are @Generable and @Guide?

@Generable is a macro that marks Swift structures for generation by language models. Instead of getting raw text from an LLM and parsing it manually, developers can now specify a structure and ask the model to generate objects that match it. This approach is more reliable than text-based generation because the model works with a predefined format.

@Guide complements @Generable by providing hints at the field level. With @Guide, developers can specify what each field should contain, giving the model more context for accurate generation. For example, if a field expects a summary, you can tell the model: "This field should contain a brief description, no more than two sentences."

How does structured generation work?

The process is straightforward. First, you define a Swift structure and mark it with @Generable. Then you use a LanguageModelSession to send a prompt to the model. The model understands the structure and returns data that matches your type definition. This eliminates the need for string parsing and reduces the chance of errors.

Apple provides streaming support, so as the model generates data, your app receives chunks progressively. This allows UI updates to happen in real-time instead of waiting for the complete response. SwiftUI integration makes it easy to bind these updates to the interface.

Why @Guide matters

Without @Guide, the model might interpret fields ambiguously. With it, developers gain fine-grained control. Here are the main benefits:

  • Clarity — the model understands exactly what each field should contain
  • Validation — hints reduce the likelihood of incorrect or irrelevant data
  • Consistency — across multiple generations, outputs remain predictable
  • Efficiency — fewer retries needed because the first attempt is more likely to succeed
  • Type safety — integration with Swift's type system prevents runtime errors

The bigger picture

Apple's approach represents a shift from fragile text parsing to structured, type-safe AI integration. Instead of prompting for natural language and hoping the output can be parsed, developers now work with language models as data generators. This makes AI features more reliable and easier to integrate into production apps. The macros handle the complexity, leaving developers free to focus on their application logic.

Story

Key Questions Answered

What are @Generable and @Guide?

@Generable is a macro that marks Swift structures for generation by language models. Instead of getting raw text from an LLM and parsing it manually, developers can now specify a structure and ask the model to generate objects that match it. This approach is more reliable than text-based generation because the model works with a predefined format. @Guide complements @Generable by providing hints at the field level. With @Guide, developers can specify what each field should contain, giving the model more context for accurate generation. For example, if a field expects a summ

How does structured generation work?

The process is straightforward. First, you define a Swift structure and mark it with @Generable. Then you use a LanguageModelSession to send a prompt to the model. The model understands the structure and returns data that matches your type definition. This eliminates the need for string parsing and reduces the chance of errors. Apple provides streaming support, so as the model generates data, your app receives chunks progressively. This allows UI updates to happen in real-time instead of waiting for the complete response. SwiftUI integration makes it easy to bind these upda

What are the key details on Apple showed how @Generable and @Guide macros in FoundationModels simplify Swift development?

Apple continues to improve its approach to integrating artificial intelligence into Swift. The latest step is the @Generable and @Guide macros, which allow developers to work with structured generation from language models in a type-safe way.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…