BPFormatted

This is a back-port of the .formatted API in Foundation that was introduced at WWDC ’21 for iOS 15, macOS 12.0, tvOS 15.0, and watchOS 8.0.

Most developers cannot start developing their apps from those platforms and upwards.

But now they can! This package provides the same nice api for projects starting at iOS 9.0, macOS 10.10, tvOS 9.0 and watchOS 2.0!!!

Goal

To provide the exact same api with the exact same results as Apple’s Foundation api.

Features

What’s already available and what’s to come.

  • Date
  • ISO8601 (iOS 10, macOS 10.12, watchOS 3, tvOS 10)
  • DateInterval
  • Relative Dates (iOS 15, macOS 10.15, watchOS 6, tvOS 13)
  • List
  • Measurement
  • PersonNameComponent
  • RelativeDate
  • ByteCount
  • String parsing (maybe)

How to use

The same API as in Apple’s Foundation framework, but prefixed with bp.

<div class="highlight highlight-source-swift position-relative" data-snippet-clipboard-copy-content="// Apple's Foundation
Date().formatted()
Date().formatted(.dateTime.month().year(.twoDigits))
(Date()..<Date()).formatted(.interval.year())
// BPFormatted
Date().bpFormatted()
Date().bpFormatted(.dateTime.month().year(.twoDigits))
(Date()..

// Apple's Foundation
Date().formatted()
Date().formatted(.dateTime.month().year(.twoDigits))
(Date()..<Date()).formatted(.interval.year())
// BPFormatted
Date().bpFormatted()
Date().bpFormatted(.dateTime.month().year(.twoDigits))
(Date()..<Date()).bpFormatted(.interval.year())