Last active
July 18, 2022 22:50
-
-
Save rock3m/ee925b14ece3eca01b81868271a0c7df to your computer and use it in GitHub Desktop.
Example of using SectionedFetchQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct WorkHistoryView: View { | |
@SectionedFetchRequest<String, WorkHistoryEntry>( | |
sectionIdentifier: \.createdAtDate, | |
sortDescriptors: [SortDescriptor(\.createdAt, order: .reverse)] | |
) | |
private var historyEntrySections: SectionedFetchResults<String, WorkHistoryEntry> | |
var body: some View { | |
List { | |
ForEach(historyEntrySections) { historyEntrySection in | |
Section(header: Text(historyEntrySection.id)) { | |
ForEach(historyEntrySection) { historyEntry in | |
WorkHistoryEntryView(historyEntry: historyEntry) | |
} | |
}.headerProminence(.increased) | |
} | |
}.navigationTitle("history_title") | |
} | |
} | |
extension WorkHistoryEntry { | |
@objc | |
var createdAtDate: String { | |
let formatter = DateFormatter() | |
formatter.dateStyle = .long | |
formatter.doesRelativeDateFormatting = true | |
return formatter.string(from: self.createdAt!) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment