Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of unresolved identifier "Form"

Tags:

swift

swiftui

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'

like image 614
Mane Manero Avatar asked Nov 17 '25 10:11

Mane Manero


1 Answers

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:

enter image description here

like image 88
Matteo Pacini Avatar answered Nov 20 '25 00:11

Matteo Pacini