I'm working on an app that will display some data I have collected into a Chart. Since there's quite a few different arrays I want to use, I want to be able to update the ForEach inside the chart to display the chosen array from a picker, but I'm not sure how to turn this string selectedset into something the ForEach can read and recognise as an array. Does anyone know how to do this?
private var dataSet1 = [/* set1 elements here */]
private var dataSet2 = [/* set2 elements here */]
@State private var selectedSet = dataSet1
var body: some View {
Chart {
ForEach(selectedSet, id: \.id) { data in
// REST OF FOREACH STUFF HERE
}
// Other Chart components or modifications can be added here
}
}
I tried a couple different things, including putting selectedset into the ForEach by itself but it still didn't work.
As you haven't mentioned whether the data type is the same or not for each array, two cases are possible. You can handle something like this.
Case 1: If DataType is same for each array
Case 2: If DataType is different for each array