Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Group records by a calendar-aware day key, sort the resulting groups, and display each group in a SwiftUI Section inside a List. Keep the date used for grouping separate from the localized date string shown to readers, and use stable model IDs for rows.
Choose what “same day” means
A Date represents a point in time, not a calendar day. Decide which calendar and time zone define a day for your app before grouping records. For a personal activity feed, the viewer’s current calendar is often appropriate. For a shared schedule or business record, use the calendar and time zone specified by the domain rather than allowing each viewer’s settings to shift entries between days.
As an Amazon Associate I earn from qualifying purchases.
For calendar-day grouping, use Calendar.startOfDay(for:) to turn each timestamp into a day key. This avoids treating two timestamps on the same day as different groups, and avoids using a formatted label—which can vary by locale—as a data key. Apple documents calendar date operations in Calendar.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallGroup and order the records
Here is one implementation pattern for entries grouped newest-first, with the newest entry first within each day:
#1 Best Overall
import SwiftUI
struct Entry: Identifiable {
let id: UUID
let date: Date
let title: String
}
struct DayGroup: Identifiable {
let day: Date
let entries: [Entry]
var id: Date { day }
}
func groupedByDay(
_ entries: [Entry],
calendar: Calendar = .current
) -> [DayGroup] {
let grouped = Dictionary(grouping: entries) { entry in
calendar.startOfDay(for: entry.date)
}
return grouped.keys.sorted(by: >).map { day in
DayGroup(
day: day,
entries: grouped[day, default: []].sorted { $0.date > $1.date }
)
}
}
The function makes the ordering explicit: dictionary key iteration does not define a timeline’s chronology. Reverse the comparison to < for oldest-first sections and rows, as in a forward-looking agenda. If the source already guarantees the desired row order, you can omit the inner sort.
The example uses each day’s start as a group ID because a day appears only once in the returned array. Keep each entry’s persistent unique ID for its row; an array index is not a reliable identity when data can be inserted, deleted, or reordered. Apple’s Displaying data in lists guide explains how SwiftUI uses identifiable data to track changes.
Rank #2
Display each day as a SwiftUI section
Use a List for the vertical collection, a Section for each date heading, and a nested ForEach for that day’s entries:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →struct EntryList: View {
let groups: [DayGroup]
var body: some View {
List {
ForEach(groups) { group in
Section {
ForEach(group.entries) { entry in
Text(entry.title)
}
} header: {
Text(
group.day,
format: .dateTime.month(.wide).day().year()
)
}
}
}
}
}
The date format is for presentation; it does not determine membership in a group. Date.FormatStyle provides a Swift-friendly way to create localized date output. See Apple’s DateFormatter documentation for date formatting and its reference to Date.FormatStyle.
Rank #3
Choose where grouping belongs
You can compute groups before passing them to the view, or derive them while composing the view. Neither approach is required by SwiftUI; choose based on how the data is used.
| Approach | Useful when | Trade-off |
|---|---|---|
Precompute a [DayGroup] in a model or view-model layer |
Several screens need the same grouping, or you want to test and reason about the transformation separately from rendering. | You must refresh the derived groups when the source records or relevant calendar settings change. |
| Group inline while building the view | The collection is small and static, and keeping the transformation close to the rendering is convenient. | Reuse and isolated testing can be less straightforward as the view grows. |
For pagination or frequently changing data, ensure each update rebuilds or updates the groups from the current records, then preserve stable entry IDs. If the app lets users change calendar or time-zone settings while the view remains visible, recompute the day keys under the new settings.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Handle empty dates and common grouping mistakes
- Do not group by a display string. A label is localized presentation, not a dependable calendar key.
- Do not compare full timestamps for day equality. Different times on one calendar day are still different
Datevalues. - Do not silently use UTC for a local-day interface. Entries close to midnight can appear under a different day than users expect.
- Do not rely on dictionary order. Sort section keys, and sort rows when their source order is not meaningful.
- Generate empty dates separately if the design needs them. Grouping records creates only groups that contain records. To show dates with no entries, create the desired date range and render empty sections intentionally.
Apple’s SwiftUI list guide describes the view structure: a List can contain sections and rows, with each row represented by a SwiftUI view. The date-key logic and ordering remain application decisions; the example above is a practical pattern, not an Apple-prescribed grouping architecture.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsQuick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




