Fill the blank
Fill the blank to declare state directly in the preview.
#Preview("Wi-Fi toggle") {
____ @State var isOn = true
Toggle("Wi-Fi", isOn: $isOn)
.padding()
}Hint 1 of 1
The macro's name mentions previews.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A @Previewable
Correct. It lets the preview own state without a wrapper view.
Why not the others?
- B
@Environment. Environment reads values; it doesn't declare state. - C
@Bindable. Bindable is for @Observable objects, not state in previews. - D
@MainActor. Isolation doesn't make state work in a preview.