I've been trying to replicate Apple WWDC 19 example below - converting a SwiftUI VStack into a Form - to no avail.
Here's the video mentioning Form:
https://developer.apple.com/videos/play/wwdc2019/216/ (34:08)
Here is the code I am using for VStack:
import SwiftUI
struct ContentView : View {
var body: some View {
VStack {
Toggle(isOn: .constant(true)) {
Text("Toggle")
}
Stepper(value:.constant(4), in: 1...10) {
Text("Stepper")
}
Text("Hello World")
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
And here is the code I am using for Form:
import SwiftUI
struct ContentView : View {
var body: some View {
Form {
Toggle(isOn: .constant(true)) {
Text("Toggle")
}
Stepper(value:.constant(4), in:1...10) {
Text("Stepper")
}
Text("Hello World")
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
The error I'm getting in the last snippet:
Use of unresolved identifier 'Form'
It seems like Form is not part of SwiftUI yet (?).
But you can use a grouped list to achieve the same result.
struct ContentView: View {
var body: some View {
List {
Section(header: Text("Section").font(.largeTitle)) {
Text("Text")
Toggle(isOn: .constant(true)) { Text("Toggle") }
}
}.listStyle(.grouped)
}
}
It is available as of Beta 2.
Your code...
struct ContentView : View {
var body: some View {
Form {
Toggle(isOn: .constant(true)) {
Text("Toggle")
}
Stepper(value:.constant(4), in:1...10) {
Text("Stepper")
}
Text("Hello World")
}
}
}
...produces this output:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With