Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


A Swift Formatter Kit

Subscribe to updates I use Format

Statistics on Format

Number of watchers on Github 1160
Number of open issues 3
Average time to close an issue 14 days
Main language Swift
Average time to merge a PR about 3 hours
Open pull requests 1+
Closed pull requests 1+
Last commit about 3 years ago
Repo Created about 4 years ago
Repo Last Updated over 1 year ago
Size 134 KB
Organization / Authormarmelroy
Latest Release0.5.0
Page Updated
Do you use Format? Leave a review!
View open issues (3)
View Format activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating Format for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Format - a Swift Formatter Kit

Build Status Version Carthage compatible


A Swift formatter kit. Simple formatting syntax for decimal numbers, currency, mass, addresses, ordinal numbers and hexadecimal colors.


Import Format at the top of the Swift file with the content you would like to format.

import Format

Number Formatting

Format provides a formatting extension for all number types. To format an Int to two decimal places:

let formattedNumber = 45.format(Decimals.two) // 45.00

Format defaults to the user's current locale but a custom locale can be easily provided:

let frLocale = Locale(identifier: "FR")
let gbLocale = Locale(identifier: "GB")
let formattedFRNumber = 99.format(Currency.EUR, locale: frLocale) // 99,00
let formattedGBNumber = 99.format(Currency.GBP, locale: gbLocale) // 99.00

Apply any of these formatters to any number type:

Decimals.three // 10.123
Currency.USD // $10.12
General.ordinal // 10th (iOS9+ only)
General.spellOut // ten point one two three
General.distance // 30 feet
Mass.person // 67 kg

The distance formatter assumes the number represents the distance in meters before converting and formatting it to the current locale's preferred unit.

Address Formatting (iOS9.0+ only)

Different cultures have different ways of displaying addresses. Format includes an extension on CLPlacemark that converts the addressDictionary to a formatted string in the current locale:

let address = placemark.format()

Please note that this function will produce a deprecated warning when used. This is because Apple is using AddressBook keys in the CLPlacemark and AddressBook was deprecated.

To format a custom address (all fields are optional strings):

let address = AddressFormatter().format(street, city: city, state: state, postalCode: postalCode, country: country, ISOCountryCode: ISOCountryCode)

Color Formatting

Format can help you convert hexadecimal colors from the web to UIColors you can work with:

let color = ColorFormatter().format("2ba134")

In case of an error, the color will default to black if the string is empty or white if the string is invalid.

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Format into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/Format"

Setting up with CocoaPods

source ''
pod 'Format', '~> 0.5'
Format open pull requests (View All Pulls)
  • Update to swift 4
Format questions on Stackoverflow (View All Questions)
  • Output for finding the time in 24 hour input given in 12hour format(without using any inbuild class)
  • Is is possible to position an element offscreen using Visual Format Language?
  • DateTime::Format::CLDR issues parsing long Czech dates
  • excel cell custom format multiply by 1000
  • Can we generate output of a JUNOS command in xml format
  • Export table to file twice due to incorrect format
  • How to format date in libre office
  • C# asp replacing table control retains old format
  • RTF format: How to fit the cell width to RichEdit width?
  • Convert object a to match format of object b and merge them JavaScript
  • Trying to import the private key into a PKCS12 format key store, but instead I get usage note
  • Working with a string in JSON format
  • How to format time(0) SQL data field as AM/PM using GridView DataFormatString property
  • What is the proper json format for output of remote in typeahead.js?
  • get content from all rows of a UITableView section and format using UIPrintPageRenderer
  • Is there any way to convert csv to json format in Amazon web services
  • Variable Interpolation vs. Substitution in printf Format String
  • uploading using Mashape to upload to imgur always says image corrupted or not format not supported
  • regex: include the day optional in a variable date-format
  • Converting text file to certain format c#
  • Proper HLS format?
  • moment js format date
  • PHP Convert to YouTube Time Format (ISO 8601)
  • Change format of the Source map created from closure compiler
  • Want to Convert decimal value in 2 raised to format and want to know its power of 2 in java
  • Format labels produced by cut() as percentages
  • Ho do I check whether a phone time format is set to 24 hours?
  • RABL: change default date and time format to iso8601
  • How do I fix "Unrecognized Guid format"
  • using hex to find file format
Format list of languages used
Format latest release notes
0.5.0 Format 0.5.0
  • Official Swift 3 release
0.3.0 Format 0.3.0
  • Adding iOS8 support.
0.2.0 Format 0.2.0
  • Added mass formatter and infrastructure for formatters that don't allow custom locales.
  • Code refactoring (thanks @aashishdhawan)
Other projects in Swift