SwiftUI Previewable Macro Note

SwiftUI Previewable Macro

1. Apple's Previewable macro in iOS 18 generates boilerplate wrapper views for SwiftUI previews with State bindings. 2. SwiftUI previews can enhance the view creation experience but often require container views with state bindings. 3. The Previewable macro eliminates the need for manual wrapper views by declaring @State properties directly in the Preview. 4. The macro creates a wrapper view with the necessary state properties. 5. To use the Previewable macro, mark @State properties at the Preview root with the @Previewable macro. 6. The macro transforms into a wrapper view containing the state properties and the preview view. 7. The wrapper view generated by the Previewable macro resembles manually created wrapper views. 8. The Previewable macro simplifies the creation of interactive SwiftUI previews with state bindings. 9. It reduces the boilerplate code required for wrapper views, streamlining the development process. 10. Refer to WWDC24's "What's new in SwiftUI" for more information on the Previewable macro and other SwiftUI advancements.