Previewable()
Tag allowing a dynamic property to appear inline in a preview.
Declaration
@attached(peer) macro Previewable()Overview
Tagging a variable declaration at root scope in your #Preview body with ‘@Previewable’ allows you to use dynamic properties inline in previews. The #Preview macro will generate an embedded SwiftUI view; tagged declarations become properties on the view, and all remaining statements form the view’s body.
#Preview("toggle") {
@Previewable @State var toggled = true
return Toggle("Loud Noises", isOn: $toggled)
}It is an error to use @Previewable outside of a #Preview body closure.