Reputation: 1122
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
Upvotes: 3
Views: 3925
Reputation: 1081
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
Upvotes: 0
Reputation: 1184
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) }
Upvotes: 1
Reputation: 8193
ForEach
syntax changed a little bit in Beta 5.
Have you tried:
ForEach(state.modes, id: \.self) { mode in
Text(mode)
}
Upvotes: 11
Reputation: 2154
As per the apple release note, it's known issue from their end. We have to wait for another release.
Upvotes: 1