使用未解决的标识符“表单”

Man*_*ero 3 swift swiftui

我一直在尝试复制下面的Apple WWDC 19示例-将SwiftUI VStack转换为Form-无济于事。

这是提到的视频Form

https://developer.apple.com/videos/play/wwdc2019/216/34:08

这是我用于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
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码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
Run Code Online (Sandbox Code Playgroud)

我在上一个片段中遇到的错误:

使用未解决的标识符“表格”

Mat*_*ini 6

似乎Form还不是SwiftUI的一部分(?)。

但是您可以使用分组列表来达到相同的结果。

struct ContentView: View {

    var body: some View {
        List {
            Section(header: Text("Section").font(.largeTitle)) {
                Text("Text")
                Toggle(isOn: .constant(true)) { Text("Toggle") }
            }
        }.listStyle(.grouped)
    }

}
Run Code Online (Sandbox Code Playgroud)


从开始提供Beta 2

您的代码...

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")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

...产生以下输出:

在此处输入图片说明