In Ruby, we have symbols to use for the key of hashes. I'm trying to port a Ruby library to Objective-C, and the library has a hash in it that uses symbols as keys. Is there any similar soulution for Objective-C? Or should I be using NSString
s?
0
votes
2 Answers
2
votes
I've seen declarations like
extern NSString *const NSKeyValueChangeNewKey = @"NSKeyValueChangeNewKey";
so that you can use it as a key:
[dict objectForKey:NSKeyValueChangeNewKey];
For an explanation that's a bit more detailed, see Constants in Objective-C.
#define
constants to achieve a similar outcome. – Sahand