How to use the previewable macro
Asked on 06/12/2025
1 search
The "previewable" macro is a new feature introduced to enhance the way previews are created in Xcode. It allows developers to use dynamic properties like state directly within an Xcode preview, reducing the amount of boilerplate code needed. This macro can be attached to property wrappers such as state, enabling you to define your state right in the previews body. This tells the preview system to create a wrapper view behind the scenes, simplifying the process of setting up previews.
For example, in the session What’s new in Xcode 16, it is explained that the previewable macro can be used to attach to property wrappers like state, allowing you to use them directly within a preview block. This eliminates the need for writing wrapper views, making the process more efficient and streamlined.
Additionally, in the session What’s new in SwiftData, the previewable macro is used to create queries right in the preview declaration, providing an array of models that can be passed to views for creating previews with sample data.
These enhancements make it easier to iterate on UI designs and test different states of your app's interface quickly.

What’s new in SwiftData
SwiftData makes it easy to add persistence to your app with its expressive, declarative API. Learn about refinements to SwiftData, including compound uniqueness constraints, faster queries with #Index, queries in Xcode previews, and rich predicate expressions. Join us to explore how you can use all of these features to express richer models and improve performance in your app. To discover how to build a custom data store or use the history API in SwiftData, watch “Create a custom data store with SwiftData” and “Track model changes with SwiftData history”.

What’s new in Xcode 16
Discover the latest productivity and performance improvements in Xcode 16. Learn about enhancements to code completion, diagnostics, and Xcode Previews. Find out more about updates in builds and explore improvements in debugging and Instruments.

Platforms State of the Union
Discover the newest advancements on Apple platforms.