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.
views:
117answers:
4Since 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.
Use [NSLocale ISOCurrencyCodes]
. It gives you an array of all the ISO currency codes as strings.
CFLocaleCopyCommonISOCurrencyCodes();
CFLocaleCopyISOCurrencyCodes();
[NSLocale commonISOCurrencyCodes];
[NSLocale ISOCurrencyCodes];
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.