Showing posts with label ISOCurrencyCodes example. Show all posts
Showing posts with label ISOCurrencyCodes example. Show all posts

Saturday, May 11, 2013

NSLocale ISOCurrencyCodes example ios


ISOCurrencyCodes

Returns an array of NSString objects that represents all known legal ISO currency codes.
+ (NSArray *)ISOCurrencyCodes
Return Value
An array of NSString objects that represents all known legal ISO currency codes.
Discussion of [NSLocale ISOCurrencyCodes]
Note that some of the currency codes may not have any supporting locale data in OS X.
Example of [NSLocale ISOCurrencyCodes]
NSLocale *locale = [NSLocale currentLocale];
for (NSString *code in [NSLocale ISOCurrencyCodes]) {
    NSLog(@"%@ : %@", code, [locale displayNameForKey:NSLocaleCurrencyCode value:code]);
}
Example of [NSLocale ISOCurrencyCodes]
NSArray *countryArray = [NSLocale ISOCurrencyCodes];
    for(NSString *country in countryArray)
    {
        //NSLog(@"%@",[[NSLocale currentLocale] displayNameForKey:NSLocaleCurrencyCode value:country]);
        if([[NSLocale currentLocale] displayNameForKey:NSLocaleCurrencyCode value:country])
        {
        [countriesArray addObject:[[NSLocale currentLocale] displayNameForKey:NSLocaleCurrencyCode value:country]];
        }
    }
Example of [NSLocale ISOCurrencyCodes]
-(void) showCurrenciesList
{
    NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];                         
    [numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    //[numFormatter setLocale: [NSLocale currentLocale]];

    NSMutableArray *aryAllCurrencies = [[NSMutableArray alloc] init]; 
    //NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier: @"en_US"] autorelease];

    NSArray *currencyArray = [NSLocale ISOCurrencyCodes]; 
    NSLog(@"Currency array : %@",currencyArray);

    for (NSString *currencyCode in currencyArray) 
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        [numFormatter setCurrencyCode:currencyCode];
        NSString *currencySymbol = [numFormatter currencySymbol];
        [aryAllCurrencies addObject:currencySymbol];
        [pool release];     
    }   
    //[countriesArray sortUsingSelector:@selector(compare:)];
    NSLog(@"currencies array : %@",aryAllCurrencies);   
}