将 ForEach 与字符串数组一起使用 - [String] 没有成员“已识别”

fde*_*nte 2 swift swiftui

我正在使用 Xcode 11 beta 5 并且我所拥有的不再起作用。这是我的代码:

struct ModeView : View {
  @EnvironmentObject var state: IntentionState

  var body: some View {
      Picker(selection: $state.selection, label: Text("")) {
        ForEach(state.modes.identified(by: \.self)) { mode in
          Text(mode)
        }
      }.pickerStyle(SegmentedPickerStyle())
  }
}
Run Code Online (Sandbox Code Playgroud)

错误在行中ForEach(uistate.modes.identified(by: \.self)) { mode in,它说:

“[String]”类型的值没有“已识别”成员

当我使用 Xcode 11 beta 4 时,它运行良好。现在的问题是如何在 Xcode beta 5 中使用 ForEach 和数组字符串

bac*_*h-f 10

ForEach Beta 5 中的语法略有变化。

你有没有尝试过:

ForEach(state.modes, id: \.self) { mode in
    Text(mode)
}
Run Code Online (Sandbox Code Playgroud)