I know that Objective-C allows me to refer to selectors by name using @selector(@"name")
How can I access the following constant by name at runtime? In other words, I would pass @"CONST_KEY"
somewhere and get @"key"
back.
const NSString* CONST_KEY = @"key";
I think I can do this by first creating a key-value dictionary and then querying it at runtime, but I'm not sure if there's a better implementation.
To clarify with a specific use case:
I want to use a collection view cell reuse identifier @"CONST_KEY"
, declared in my storyboard, and to be able to use this identifier to look up the value of CONST_KEY
at runtime.
This way I hope to have a single place within my code to modify constants, rather than having to re-assign values in multiple classes. Having the two values linked will allow me to have a single action for all those cells using the CONST_KEY
to define the action they are going to do.