Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Why limit yourself to those 26 ASCII characters? Is Unicode not supported?

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.
 

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
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..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.