formatted(_:referenceDate:)
Formats the subscription period using a format style that takes a date range as an input.
Declaration
@backDeployed(before: iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, macCatalyst 16.0)
func formatted<S>(_ format: S, referenceDate: Date = .now) -> S.FormatOutput where S : FormatStyle, S.FormatInput == Range<Date>Parameters
- format:
A format style that has a date range input. The format style for a product is Subscriptionperiodformatstyle.
- referenceDate:
The lower bound date for a date range representing the subscription period. The default value is Now.
Discussion
Use the formatted(_:referenceDate:) method with subscriptionPeriodFormatStyle to format the subscription period for the App Store locale, as the following example shows.
// Get a human-readable representation of a subscription period.
subscriptionPeriod.formatted(product.subscriptionPeriodFormatStyle, referenceDate: /* some date */)