Last active
August 29, 2015 14:19
-
-
Save Abizern/8a4b1bce8d970b8f0f39 to your computer and use it in GitHub Desktop.
You don't need to declare a custom class to have a singleton formatter, just use a global lazy var.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var formatter: NSNumberFormatter = { | |
let f = NSNumberFormatter() | |
f.locale = NSLocale.currentLocale() | |
f.maximumFractionDigits = 2 | |
f.minimumFractionDigits = 2 | |
f.alwaysShowsDecimalSeparator = true | |
f.numberStyle = .CurrencyStyle | |
return f | |
}() | |
let a = formatter | |
let b = formatter | |
a === b // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment