3

I'm using Xcode 11 beta 5 and what I had it doesn't work anymore. This is my code:

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())
  }
}

The error is in the line ForEach(uistate.modes.identified(by: \.self)) { mode in and it says:

Value of type '[String]' has no member 'identified'

When I was using Xcode 11 beta 4 it worked perfectly. The question now is how to use ForEach with an array string in Xcode beta 5

4 Answers 4

11

ForEach syntax changed a little bit in Beta 5.

Have you tried:

ForEach(state.modes, id: \.self) { mode in
    Text(mode)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's the solution
1

As per the apple release note, it's known issue from their end. We have to wait for another release.

https://developer.apple.com/documentation/ios_ipados_release_notes/ios_ipados_13_beta_5_release_notes

enter image description here

2 Comments

What would it be a complex expression? In my case, what I have in the closure seems to be very simple
@fdelafuente What happens if you try extracting that expression to a separate variable, and pass the variable to ForEach?
1

The identified(by:) method has been deprecated, the correct syntax is now:

init(Data, id: KeyPath<Data.Element, ID>, content: (Data.Element) -> Content)

or after moving the content into a closure :

ForEach(state.modes, id: \.self) { mode in Text(mode) }

Comments

0

let suppose you have a name array like this:

let names = ["mike","Jack","jill"]

ForEach(names, id: \.self) { Text($0) }

Text($0) - this will print all elements from your names array.

Note:

Use backslashsign.self instead .self, somehow backslash sign is not working here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.