I need a string->string mapping to be used at runtime (think NSDictionary), except the mapping will NEVER change after build-time.
The naive solution is to just use an NSDictionary, but there has to be a more optimal way to do this, no?
Optimal in the sense that if the mapping is known at compile-time, and known to never change, the compiler should be able to do the mapping at compile-time. An NSDictionary needs to do a hash lookup at runtime. I know it’s constant time, but it just feels a bit “unclean” to me…
A static
NSDictionaryis the right tool for this. You typically initialize these with an+initializemethod:initializeis called one time per class, with thread safety, immediately before the first requested method is called on that class (usually this first method is+alloc). Theselftest is because subclasses will automatically call their[super initialize], and you generally don’t want to run this more than once in that case.