SystemFormatStyle
A collection of format styles for displaying live-updating time information in Text views.
Declaration
enum SystemFormatStyleOverview
Use the format styles in this namespace to present time-based data that automatically updates as the system clock advances. Each style formats a Date value into an AttributedString and conforms to both FormatStyle and DiscreteFormatStyle, allowing SwiftUI to efficiently schedule text updates at exactly the right moments.
You typically use these styles with the Text/init(_:format:)-2rl92 initializer:
let startDate = Date.now
let endDate = startDate.addingTimeInterval(300)
Text(.currentDate, format: .offset(to: startDate))
// Output: "3 minutes, 42 seconds"
Text(.currentDate, format: .stopwatch(startingAt: startDate))
// Output: "00:03.42"
Text(.currentDate, format: .timer(countingDownIn: startDate..<endDate))
// Output: "4:17"
Text(.currentDate, format: .reference(to: endDate))
// Output: "in 5 minutes"Choosing a Style
Style | Purpose | Example Output |
|---|---|---|
Elapsed time since or until a date |
| |
Precision stopwatch counting up |
| |
Countdown or count-up within a bounded interval |
| |
Natural-language reference to a date |
|