xcode - Display location based currency identifiers in text field placeholder -
Basically I have pounds and pence value two text fields for input within my app I'm currently your app to the user like I am working on creating localized and I need to have participated in a problem placeholders pounds and pence in my Tekstfeld and display I placeholders based on the exchange of users and sub-currency ' Olrs' and based on locations such as St.
I do not know how to do that which would be efficient and I was hoping for some suggestions how I could go about it.
Any help would be greatly appreciated!
You can get the name of the local currency using NSLocale:
var locale = NSLocale.currentLocale () var CurrencyCode: (! AnyObject) = locale.objectForKey (NSLocaleCurrencyCode) locale.displayNameForKey (NSLocaleCurrencyCode, price: code) // "GBP"
< P> However, it seems that you can not be satisifed with the official name and I can create your own list using a number of places identifiers so you can also get pence or cents about Switch to I do not know: struct LocalCurrency {static completely full name (forLocale Lou Cale: NSLocale = NSLocale.currentLocale ()) - & gt; String {var identifier: String = locale.localeIdentifier switch (identifiers) {case "En_UK" return "pound" case "En_US" return "dollar" default: return ""}}} LocalCurrency.wholeName () // "Pound "
You can create the same method for partial currencies and you have to add all the locals you want to support manually, but at least the device will tell you that What is locale? / P>
Update:
You can also find currency symbols:
locale.displayNameForKey (NSLocaleCurrencySymbol, price: code ) // £
or you can use a NSNumberFormatter to exchange format for you:
var formatter = NSNumberFormatter () formatter .numberStyle = .CurrencyStyle Formatter StringFromNumber (1.23) // 1.23 £
Perhaps you can use one of those to create a new format to display it without making a manual list.
Comments
Post a Comment