Swift 格式化庫 Format,可以對數(shù)字、貨幣、地址、十六進制顏色進行格式化。
示例代碼:
let formattedNumber = 45.format(Decimals.Two) // 45.00 let frLocale = NSLocale(localeIdentifier: "FR") let gbLocale = NSLocale(localeIdentifier: "GB") let formattedFRNumber = 99.format(Currency.EUR, locale: frLocale) // 99,00 € let formattedGBNumber = 99.format(Currency.GBP, locale: gbLocale) // £ 99.00 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 let address = placemark.format() let color = ColorFormatter().format("2ba134")