One Logo Pool Ball
Foundation · IOS API REFERENCE

Date.AnchoredRelativeFormatStyle

struct · iOS 18.0+ · SDK 27.1

struct AnchoredRelativeFormatStyle

A relative format style that is detached from the system time, and instead formats an anchor date relative to the format input.

Members (22)

get · iOS 18.0+

unitsStyle

TypeScript
get unitsStyle(): Date_RelativeFormatStyle_UnitsStyle
Swift declaration
var unitsStyle: Date.AnchoredRelativeFormatStyle.UnitsStyle { get set }
set · iOS 18.0+

unitsStyle

TypeScript
set unitsStyle(value: Date_RelativeFormatStyle_UnitsStyle)
Swift declaration
var unitsStyle: Date.AnchoredRelativeFormatStyle.UnitsStyle { get set }
get · iOS 18.0+

presentation

TypeScript
get presentation(): Date_RelativeFormatStyle_Presentation
Swift declaration
var presentation: Date.AnchoredRelativeFormatStyle.Presentation { get set }
set · iOS 18.0+

presentation

TypeScript
set presentation(value: Date_RelativeFormatStyle_Presentation)
Swift declaration
var presentation: Date.AnchoredRelativeFormatStyle.Presentation { get set }
get · iOS 18.0+

allowedFields

TypeScript
get allowedFields(): Array<Date_ComponentsFormatStyle_Field>
Swift declaration
var allowedFields: Set<Date.AnchoredRelativeFormatStyle.Field> { get set }

The fields that can be used in the formatted output.

set · iOS 18.0+

allowedFields

TypeScript
set allowedFields(value: Array<Date_ComponentsFormatStyle_Field>)
Swift declaration
var allowedFields: Set<Date.AnchoredRelativeFormatStyle.Field> { get set }

The fields that can be used in the formatted output.

method · iOS 18.0+

discreteInput

TypeScript
discreteInputAfter(input: globalThis.Date): (globalThis.Date) | null
Swift declaration
func discreteInput(after input: Date) -> Date?

The next discretization boundary after the given input. Use this function to determine the next "greater" input that warrants updating the formatted output. The following example prints all possible outputs the format style can produce upwards starting from the `startInput`: ```swift var previousInput = startInput while let nextInput = style.discreteInput(after: previousInput) { print(style.format(nextInput)) previousInput = nextInput } ``` - Returns: For most `input`s, the method returns the "smallest" value "greater" than `input` for which the style produces a different ``FormatStyle/FormatOutput``, or `nil` if no such value exists. For some input values, the function may also return a value "greater" than `input` for which the style still produces the same ``FormatStyle/FormatOutput`` as for `input`.

method · iOS 18.0+

discreteInput

TypeScript
discreteInputBefore(input: globalThis.Date): (globalThis.Date) | null
Swift declaration
func discreteInput(before input: Date) -> Date?

The next discretization boundary before the given input. Use this function to determine the next "smaller" input that warrants updating the formatted output. The following example prints all possible outputs the format style can produce downwards starting from the `startInput`: ```swift var previousInput = startInput while let nextInput = style.discreteInput(before: previousInput) { print(style.format(nextInput)) previousInput = nextInput } ``` - Returns: For most `input`s, the method returns the "greatest" value "smaller" than `input` for which the style produces a different ``FormatStyle/FormatOutput``, or `nil` if no such value exists. For some input values, the function may also return a value "smaller" than `input` for which the style still produces the same ``FormatStyle/FormatOutput`` as for `input`.

get · iOS 18.0+

capitalizationContext

TypeScript
get capitalizationContext(): FormatStyleCapitalizationContext
Swift declaration
var capitalizationContext: FormatStyleCapitalizationContext { get set }
set · iOS 18.0+

capitalizationContext

TypeScript
set capitalizationContext(value: FormatStyleCapitalizationContext)
Swift declaration
var capitalizationContext: FormatStyleCapitalizationContext { get set }
method · iOS 18.0+

input

TypeScript
inputAfter(input: globalThis.Date): (globalThis.Date) | null
Swift declaration
func input(after input: Date) -> Date?

The next input value after the given input. Use this function to determine if the return value provided by ``discreteInput(before:)`` is precise enough for your use case for any input `y`: ```swift guard let x = style.discreteInput(before: y) else { return } let z = style.input(after: x) ?? y ``` If the distance between `x` and `z` is too large for the precision you require, you may want to manually probe ``FormatStyle/format(_:)`` at a higher rate in that interval, as there is no guarantee for what the output will be in that interval. - Returns: The next "greater" input value that can be represented by ``FormatStyle/FormatInput`` or an underlying representation the format style uses internally.

method · iOS 18.0+

input

TypeScript
inputBefore(input: globalThis.Date): (globalThis.Date) | null
Swift declaration
func input(before input: Date) -> Date?

The next input value before the given input. Use this function to determine if the return value provided by ``discreteInput(after:)`` is precise enough for your use case for any input `y`: ```swift guard let x = style.discreteInput(after: y) else { return } let z = style.input(before: x) ?? y ``` If the distance between `z` and `x` is too large for the precision you require, you may want to manually probe ``FormatStyle/format(_:)`` at a higher rate in that interval, as there is no guarantee for what the output will be in that interval. - Returns: The next "smalller" input value that can be represented by ``FormatStyle/FormatInput`` or an underlying representation the format style uses internally.

init · iOS 18.0+

init

TypeScript
static initAnchorPresentationUnitsStyleLocaleCalendarCapitalizationContext(anchor: globalThis.Date, presentation?: Date_RelativeFormatStyle_Presentation, unitsStyle?: Date_RelativeFormatStyle_UnitsStyle, locale?: Locale, calendar?: Calendar, capitalizationContext?: FormatStyleCapitalizationContext): Date_AnchoredRelativeFormatStyle
Swift declaration
init(anchor: Date, presentation: Date.AnchoredRelativeFormatStyle.Presentation = .numeric, unitsStyle: Date.AnchoredRelativeFormatStyle.UnitsStyle = .wide, locale: Locale = .autoupdatingCurrent, calendar: Calendar = .autoupdatingCurrent, capitalizationContext: FormatStyleCapitalizationContext = .unknown)

Create a relative format style that is detached from the system time, and instead formats an anchor date relative to the format input. - Parameter anchor: The date the formatted output is referring to.

init · iOS 18.0+

init

TypeScript
static initAnchorAllowedFieldsPresentationUnitsStyleLocaleCalendarCapitalizationContext(anchor: globalThis.Date, allowedFields: Array<Date_ComponentsFormatStyle_Field>, presentation?: Date_RelativeFormatStyle_Presentation, unitsStyle?: Date_RelativeFormatStyle_UnitsStyle, locale?: Locale, calendar?: Calendar, capitalizationContext?: FormatStyleCapitalizationContext): Date_AnchoredRelativeFormatStyle
Swift declaration
init(anchor: Date, allowedFields: Set<Date.AnchoredRelativeFormatStyle.Field>, presentation: Date.AnchoredRelativeFormatStyle.Presentation = .numeric, unitsStyle: Date.AnchoredRelativeFormatStyle.UnitsStyle = .wide, locale: Locale = .autoupdatingCurrent, calendar: Calendar = .autoupdatingCurrent, capitalizationContext: FormatStyleCapitalizationContext = .unknown)

Create a relative format style that is detached from the system time, and instead formats an anchor date relative to the format input. - Parameter anchor: The date the formatted output is referring to.

get · iOS 18.0+

anchor

TypeScript
get anchor(): globalThis.Date
Swift declaration
var anchor: Date

The date the formatted output refers to from the perspective of the input values.

set · iOS 18.0+

anchor

TypeScript
set anchor(value: globalThis.Date)
Swift declaration
var anchor: Date

The date the formatted output refers to from the perspective of the input values.

method · iOS 18.0+

format

TypeScript
format(input: globalThis.Date): string
Swift declaration
func format(_ input: Date) -> String

Formats a value, using this style. Use this method when you want to create a single style instance, and then use it to format multiple values. - Parameter value: The value to format. - Returns: A representation of `value`, in the ``FormatOutput`` type, formatted according to the style's configuration.

get · iOS 18.0+

locale

TypeScript
get locale(): Locale
Swift declaration
var locale: Locale { get set }
set · iOS 18.0+

locale

TypeScript
set locale(value: Locale)
Swift declaration
var locale: Locale { get set }
method · iOS 18.0+

locale

TypeScript
locale88239(locale: Locale): Date_AnchoredRelativeFormatStyle
Swift declaration
func locale(_ locale: Locale) -> Date.AnchoredRelativeFormatStyle

Modifies the format style to use the specified locale. Use this format style to change the locale used by an existing format style. - Parameter locale: The locale to apply to the format style. - Returns: A format style modified to use the provided locale.

get · iOS 18.0+

calendar

TypeScript
get calendar(): Calendar
Swift declaration
var calendar: Calendar { get set }
set · iOS 18.0+

calendar

TypeScript
set calendar(value: Calendar)
Swift declaration
var calendar: Calendar { get set }

Skipped declarations

No declarations were skipped in this snapshot.

All Foundation types →