objective c - NSDictionary data shared between classes -


i creating os x app allow user play piano (using midi keyboard). notes scroll left right , user play correct note @ correct time, similar rock band or of other games. notes scrolling generated text file or sort of input source , may this:

c4 d4 b3 a3 c4 ... 

i creating dictionary music notes. in music, there 12 unique values, let's there 12 unique letter types. value of "c" 0, "c#" 1, "d" 2, etc. need codify them in way because midi data user playing produced numerically. "c" 0, data needs hardcoded. best practice sharing dictionary between multiple classes each instance of class has access it?

what best practice sharing dictionary between multiple classes each instance of class has access it?

create dictionary in class's +initialize method , store pointer in static (file-scope) variable. +initialize called before instances of class created, it's place whatever setup class needs independent of specific objects.

static nsdictionary *notesdict;  @implementation someclass  + (void)initialize {     notesdict = @{@"c" : @0, @"c#" : @1, @"d" : @2}; }  + (nsdictionary*)notes {     return notesdict; }  //...  @end 

the +notes accessor makes easy access dictionary other classes, if that's necessary.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -