tags:

views:

117

answers:

4

I wanted to allow the user to choose a currency from a list of currencies. Do i have to hardcode all the currencies in the code or can i get it from the api, somehow.

A: 

Since the list of world currencies doesn't change that often, you could go get some current definitive list and add them to your bundle as a property list (an array of strings, if that works, or a dictionary). You can load the plist with framework methods such as dictionaryWithContentsOfFile or arrayWithContentsOfFile. Storing the list in a resource is preferable to hard-coding them into your app; and since that list doesn't change that often, I don't see any reason to load them from the internet every time.

wkw
+2  A: 

Use [NSLocale ISOCurrencyCodes]. It gives you an array of all the ISO currency codes as strings.

(Link to documentation)

Nick Forge
A: 
CFLocaleCopyCommonISOCurrencyCodes();
CFLocaleCopyISOCurrencyCodes();
[NSLocale commonISOCurrencyCodes];
[NSLocale ISOCurrencyCodes];
drawnonward
A: 

I am looking at this same problem, I would like to create a choice for the user, however the larger question that comes to mind is can I identify the currency that the user's iPhone is using? I would think that the region setting would tell me the currency, and I could set that as a default, allowing the user to override.

Michael Rowe
you can get the currency associated with the current locale of the user's iphone by <code> NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init]; [formatter currencyCode]</code>
tak
Thanks... So when I would like to display the currency code, I just place currencyCode in my string?
Michael Rowe