ISO - 3166 Country codes numeric

Discussion in 'iOS Programming' started by IDMah, Mar 25, 2013.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Hi all..

    Sort of related to another problem I have, does anyone have or is there an easy way to find the numeric code for a country in xcode?

    ISO-3166 numeric 3 digit, ala:

    http://en.wikipedia.org/wiki/ISO_3166-1_numeric

    or do I have a lot of typing to do?
    Basically I want to encode a persons country and maybe city for a leader board. Hope this will not counter vein appleStore privacy policy. (Will it?)

    thanks
    Ian

    ps. I was thinking of encoding the ascii value of the letter code but seems like a lot of work also.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Why would need to do a lot of typing?

    The wikipedia article's table can be selected, copied, and pasted from a browser window. You might need to do a little cleanup, but typing it in completely from scratch seems silly.

    Also, see the References section of the Wikipedia article, and go visit the relevant website at iso.org. I suspect they provide ready access to complete tables, probably in several forms.


    As to encoding ASCII letters, why do that?

    There are 26 letters. The codes are 2 characters. That's 26*26 = 676 codes, maximum. You can treat the letters [A-Z] as digits in a base-26 numbering system, and represent the resulting number as a decimal number in less than 3 digits. How do we know no more than 3 decimal digits are needed? Because 676 is less than 999.
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    Why limit yourself to those 26 ASCII characters? Is Unicode not supported?

    Also, 900 - 999 are user assignable, so you only need to worry about 899 at most.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    The ISO-3166-1 alpha-2 codes are composed only of letters, where each letter is in the range [A-Z]. To support the entire range of alpha-2 country codes, it's only necessary to support characters in that range. Full Unicode support is not required.
     
  5. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #5
    sigh.

    Ok, I guess I'm over complicating a simple problem. Lookup table it is.

    Really I wanted people from say: Toronto, Canada to challenge play other players from their own city, country. Since Game centre only allows me
    to store the score and a context (64bit number) I wanted to encode the city and country there. I guess if I want this function I have to roll my own server.

    sigh..
     

Share This Page