Проблема здесь
Picker(selection: $selection, label: Text("")) {
ForEach(0 ..< Letters.count) {
Text(Letters[$0])
}
}
вам нужно self
с Letters
, поэтому должно быть
Picker(selection: $selection, label: Text("")) {
ForEach(0 ..< Letters.count) {
Text(self.Letters[$0])
}
}
И вторая проблема - количество просмотров, добавленных в 1 группу, Вы не можете иметь более 10 просмотров на 1 группу. Вам было бы лучше просто сделать функцию, которая заботится о переключении. и его очиститель.
Вот пример
struct Test: View {
var Letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","Number 1","Number 2","Number 3","Number 4","Number 5","Number 6","Number 7","Number 8","Number 9","Number 0","Number Sign"]
@State private var selection = 0
var body: some View {
VStack {
// Logic
getLetterView(selection: self.selection)
//END -> Logic
Picker(selection: $selection, label: Text("")) {
ForEach(0 ..< Letters.count) {
Text(self.Letters[$0])
}
}
}
}
}
func getLetterView(selection: Int) -> AnyView? {
var destination: AnyView? = nil
if selection == 0 {
destination = AnyView(LetterA())
} else if(selection == 1) {
destination = AnyView(LetterB())
} else if(selection == 2) {
destination = AnyView(LetterC())
} else if(selection == 3) {
destination = AnyView(LetterD())
} else if(selection == 4) {
destination = AnyView(LetterE())
} else if(selection == 5) {
destination = AnyView(LetterF())
} else if(selection == 6) {
destination = AnyView(LetterG())
} else if(selection == 7) {
destination = AnyView(LetterH())
} else if(selection == 8) {
destination = AnyView(LetterI())
} else if(selection == 9) {
destination = AnyView(LetterJ())
}
// Rest of your if conditions
return AnyView(NavigationView {
NavigationLink(destination: destination) {
destination
}
})
}