Swiftpack.co -  cameronshemilt/BetterToStrings as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Easily convert dates and numbers to specific string formats
.package(url: "https://github.com/cameronshemilt/BetterToStrings.git", from: "0.2.1")



Swift Package Manager

Add https://github.com/cameronshemilt/BetterToStrings to your Package Dependencies.


This Package offers improved toString() methods on the following Types:


Use toString(format: String) on a Date to receive the corresponding string to your format.

The format is the same as you would use in a DateFormatter(). An exact guide can be found here.

Preset Formats

This Package also offers some Date Format presets. You can use them via the DateFormat-enum as an optional convenience method: toString(_ dateFormat: DateFormat).

Case Date Format Example Output
.debug "YYYY-MM-dd HH:mm:ss Z" 1970-01-01 00:00:00 +0000
.date "YYYY-MM-dd" 1970-01-01
.europeanDate "dd.MM.YYYY" 01.01.1970
.americanDate "MM/dd/YYYY" 01/01/1970
.spelledDate "dd. MMMM YYYY" 01. January 1970
.spelledDateShort "dd. MMM. YYYY" 01. Jan. 1970
.time "HH:mm:ss" 00:00:00
.meridiemTime "hh:mm:ss a" 00:00:00 AM
.timeZone "Z (zzzz)" +0000 (Greenwich Mean Time)

Smart Conversion

All toString() methods for Date have a paramterer smartConbersion: Bool. This is set to false by default.

Smart conversion automatically returns "Today", "Yesterday" and "Tomorrow" if applicable. Should the Date be within one week of the current Date, the weekday will be returned (eg. "Monday", "Tuesday" etc.) .


Supported numbers are Int, Float and Double.

The function toString(abbreviation: AbbreviationStyle, maxSize: Int?, maxFractionDigits: Int?) allows you to customise the resulting String with the following parameters:

Parameter Type Default Value Description
abbreviation AbbreviationStyle .none The abbreviation style. More information can be found further below.
maxSize Int? nil The maximum count of characters the resulting string may have. This includes -, K, M etc., but excludes the decimal point.
maxFractionDigits Int? nil The maximum count of fraction digits the resulting String may have.

When maxSize or maxFractionDigits are set to nil, the size/number of fraction digits will be infinite.

Abbreviation Styles

Case Symbol Description
.none none Does not alter the number.
.thousand K Displays the number in thousands and appends a K.
.million M Displays the number in millions and appends a M.
.intelligent Depending Automatically switches the abbreviation style, depending on the size of the number.


Stars: 1
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Version 0.2.1
4 weeks ago
  • Fix various bugs

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API