I'm new to Objective C, translating existing code from Actionscript 2 for my first project. I've been trying to keep my data structures simple which for me means C-like arrays and strings rather than NS classes. I have a bunch of objects which contain a single byte char of data - they are scrabble tiles, types 'A' through 'Z'. I want to create an array of letter values in a way that the key/value pairs are easily readable and modifiable in code.
In AS2 it is simply this:
//init
letterScore = new Object({E:1, S:1, I:1, A:2, R:2 ... Z:10});
//assigned in 2dArray:
map[0]="WORD".split();
map[1]="GRID".split();
map[2]="HERE".split();
map[3]="!# @".split();
tile.letter=map[x][y];
//access
if(tile.letter>='A' && tile.letter<='Z'){
wordScore+= letterScore[tile.letter];
}
In objective C, I have already defined and read in the map in a similar fashion, my tile.letter data type is char. Is there a way to get an associative array with such simple data types as char:int pairing? Can it be done in 1 line of code similar to the AS2 init line above? The books I'm reading suggest I have to wrap the values as NSNumber, and convert between char and NSString to access them, which seems unwieldy, but if I stick with C like arrays, I lose the readability of keys. In Java I could just extend the array class to handle the casting, but the books say that's a bad idea in Objective C, so I'm completely lost.
Edit: I think to avoid the constant boxing and unboxing that people are suggesting (am I using that term right?) and to retain readability, my best option is this dreadful hack...
#define ASCII_2_ARRAY -65
int letterScore[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
// A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.
then access is simply
score += letterScore[tile.letter + ASCII_2_ARRAY];
Is there a downside to doing it this way?