I\'m trying to recreate a view that matches the event list in the stock iOS Calendar app. I have the following code which generates a list of events with each event separate
This is actually two questions.
In the data part, please upgrade userData.occurrences from [Occurrence] to [[
Occurrence
]] (I called it latestOccurrences, here)
var self.userData.latestOccurrences = Dictionary(grouping: userData.occurrences) { (occurrence: Occurrence) -> String in
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
return dateFormatter.string(from: occurrence.start)
}.values
In the swiftUI, you just reorganize the latest data:
NavigationView {
List {
ForEach(userData.latestOccurrences, id:\.self) { occurrenceSameDate in
Section(header: Text("\(occurrenceSameDate[0].start, formatter: DateFormatter.init())")) {
ForEach(occurrenceSameDate){ occurrence in
NavigationLink(
destination: OccurrenceDetail(occurrence: occurrence)
.environmentObject(self.userData)
) {
OccurrenceRow(occurrence: occurrence)
}
}
}
}
}
.navigationBarTitle(Text("Events"))
}.onAppear(perform: populate)