Slide 1

Slide 1 text

Demystifying SwiftUI previews Marina Gornostaeva | @hybridcattt

Slide 2

Slide 2 text

Agenda ! Other use-cases " Preview lifecycle # The build process $ How live reloading works ⏸ Reduce previews pausing

Slide 3

Slide 3 text

! Other use-cases

Slide 4

Slide 4 text

! Other use-cases

Slide 5

Slide 5 text

" Lifecycle of a SwiftUI preview • Build once • Live reload on changes • Pause if change is unsupported by live reloading • Repeat

Slide 6

Slide 6 text

# Build process • For DEBUG • Detect by ENABLE_PREVIEWS build setting • Use ProcessInfo in runtime

Slide 7

Slide 7 text

$ Dynamic replacement • Swift feature called @_dynamicReplacement • Pitched in 2018 • Supports changes in implementation of a function, computed variable, initializer or subscript struct MyStruct { dynamic func x() { print("x") } } extension MyStruct { @_dynamicReplacement(for: x()) func y() { print("y - replaced dynamically") } }

Slide 8

Slide 8 text

$ Limitations of live reloading • It’s applied to everything in the current ile • Supported: changes to bodies of functions, properties, initializers • Not supported: • Editing comments • Signature changes • Adding/removing types, functions, properties • Initial value changes • Changes in other iles

Slide 9

Slide 9 text

⏸ Improving live reloading • Use computed vars • Check build scripts • Auto-resume previews

Slide 10

Slide 10 text

Thanks & @hybridcattt https://hybridcattt.com/blog/ ixing-swiftui-previews