I’m attempting to populate a SwiftIO picker with a listing of calendars.
So far as I can inform, the method ought to be one thing like this:
- Declare an array of calendars:
- Populate the array within the view’s
onAppear
methodology - Populate the picker from the array.
I can’t get something to work with out some basic error. My code goes one thing like this:
Create the variable on the prime degree:
let eventStore : EKEventStore = EKEventStore()
let sources = eventStore.sources
var calendars: [EKCalendar] = []
Within the .onAppear()
methodology populate the variable:
for supply in sources {
calendars = calendars + supply.calendars(for: .occasion).sorted{ $0.title < $1.title }
}
Populate the picker:
struct ContentView: View {
@Binding var calendar: EKCalendar!
var physique: some View {
VStack {
Picker("Choose a calendar", choice: $calendar) {
// ForEach(calendars) { calendar in
// Textual content("hahaha")
// Textual content(calendar.title)
// }
}
.pickerStyle(.menu)
}
}
}
The commented out code above doesn’t work. How can I populate the picker?