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.