To ensure your SwiftUI views refresh when code is injected via HotReloading or InjectionIII, you must perform two steps in every View struct you wish to update:
- Add the
@ObserveInjection var redraw property wrapper to the struct. - Call the
.enableInjection() modifier on the view's body.
Note: In "Release" builds, these functions compile to a null operation and do not affect production performance. You can use the "Prepare Project" menu item in InjectionIII or HotReloading to automate these changes across your project.
struct MyView: View {
// 1. Add the property wrapper
@ObserveInjection var redraw
var body: some View {
// Your SwiftUI code...
Text("Hello World")
// 2. Use the enableInjection modifier
.enableInjection()
}
}