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!!!
To provide the exact same api with the exact same results as Apple's Foundation api.
What's already available and what's to come.
The same API as in Apple's Foundation framework, but prefixed with
// 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())
You will get automatic compiler warnings if you try to use this framework when your minimum deployment already allows you to use Apple's official API.
All possibilities are not yet fully documented by Apple. Your best bet right now is to watch What's new in Foundation (WWDC 2021) starting at 14:30.
.quarter(.narrow)in Apple's api results in
"2nd Quarter"while it should be
"2". My implementation does not do this. This has been reported in FB9165857
.localizedGMT(.short)in Apple's api results in
""while it should be something like
"GMT+2"My implementation does not do this. This has been reported in FB9165947
.rounded()is currently not implemented because I'm unable to get the same results as Apple
.notation(.compactName)is excluded because this is something new to Foundation and it cannot be replicated with a
DecimalTests.swiftto see which combinations.
Foundationthis is based on is still in bèta, everything is still subject to change.
// Swift 5.5 Date().bpFormatted(.dateTime) // Swift 5.x Date().bpFormatted(Date.BPFormatStyle.dateTime)
dependencies: [ .package(url: "https://github.com/simonsalomons/BPFormatted.git", .upToNextMajor(from: "0.0.1")) ]
|Last commit: 2 weeks ago|
Integer and Float number formatting