Getting a country list in Cocoa

Discussion in 'Mac Programming' started by BadWolf13, Dec 19, 2010.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I was wondering if there's a way to get a default country list from the system in Cocoa. I figure the system has a default country list, from all the options in the OS where you can choose a country, whether it's for an address, or whatever. Does this list exist, and is there a way to access it?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Take a look at NSLocale and see if that will give you what you want.
     
  3. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #3
    I don't think so. I looked through it, but couldn't find what I need. Let me try to explain it better. I'm looking to create a popUp in my program that will allow the user to select any country on earth. Now, instead of entering all these manually, I'd like to be able to populate the popUp automatically. Any idea on how to do that?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I suggest you look again. Something like this should work

    Code:
    NSMutableArray *countryNamesArray = [NSMutableArray array];
    NSLocale *current = [NSLocale currentLocale];
    for (NSString *countryCode in [NSLocale ISOCountryCodes])
    {
    [countryNamesArray addObject:[current displayNameForKey:NSLocaleCountryCode value:countryCode]];
    }
    
    Note I've not actually used this: just typed it straight into here having read the documentation I suggested you read.
     
  5. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
  6. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #6
    Lots of Stuff

    There's lots of stuff in Cocoa, thus there's lots of stuff in the documentation.

    To program in Cocoa, you need to have:
    1. The ability to program; and
    2. The ability to read and understand Cocoa documentation.

    Spend a couple of hours or days just wandering through NSString and reading the method documentation. Do that so that you understand NSString, but also so that you understand how the documentation is structured.

    Then when someone suggests you look in NSLocale or NSWhatever, you can extract the data that's in there.
     

Share This Page