[ad_1]
I need to show a SwiftData Mannequin in my Listing and have it grouped by month. So every part will checklist the gadgets with their date falling in that month. An instance could be like beneath:
@Mannequin
remaining class Merchandise {
var identify: String?
var date: Date?
init(identify: String? = nil, date: Date? = nil) {
self.identify = identify
self.date = date
}
}
struct ContentView: View {
@Question var gadgets: [Item]
var physique: some View {
let groupedDuties = Dictionary(grouping: gadgets) { (component) -> String in
return component.date!.dateString()
}
Listing {
ForEach(groupedDuties.sorted(by: { $0.key > $1.key }), id: .key) { group in
Part(header: Textual content(group)) {
ForEach(group.worth, id: .id) { merchandise in
Textual content(merchandise.identify ?? "")
}
}
}
}
}
}
This works nicely for a comparatively small variety of gadgets. However with a number of thousand gadgets the checklist slows down considerably when initially loading and turns into unusable. Is there one other strategy to kind the info into teams with out the efficiency hit?
[ad_2]