How am I going to explain this one...
Okay, I have the following class and struct set up, and updated the environment variables in SceneDelegate too:
class PointsTables: ObservableObject {
@Published var taskdata: [PointsTable] = []
}
struct PointsTable: Identifiable, Hashable {
var id = UUID()
var recordID: CKRecord.ID?
var task: String
var stretch: Int
var achievable: Int
}
I pull the data from CloudKit database which contains as task, stretch and achievable values.
In my view, i have this:
@EnvironmentObject var listTasks: PointsTables
Now I want to create a Picker with SegmentedPickerStyle, that creates just the task string from the Struct, eg:
Picker(selection: $taskSelector, label: Text("What task?")
) {
ForEach(listTasks.taskdata) { index in
Text(index.task)
}
}.padding(.bottom)
.pickerStyle(SegmentedPickerStyle())
.labelsHidden()
But this gives me a Segmented Picker, but no selection, as I can't work out how to do the ForEach with an index (which I don't think has one).
Anyone offer some advice? I feel I'm close to the solution, yet miles away.