8.9 · Previews and the macros behind SwiftUI

Previews and macros are the tooling half of modern SwiftUI. They change how quickly you see a screen in every state, and how much boilerplate the framework hides.

Mental model. A preview is a screen rendered in a chosen state. If a view cannot be previewed in that state, its dependencies are too hidden.

Tooling

<code>#Preview</code> and the macros SwiftUI relies on.

  1. How do #Preview and the macros SwiftUI uses work, and what makes a view easy to preview? 8.9.1 · L2
    #Preview is a freestanding macro: #Preview("Empty state") { ListView(items: []) } declares a preview that Xcode compiles and renders on the canvas, with no…

More in SwiftUI