I have defined a dictionary that I would like to pass around to various other objects. When they receive this dictionary, they need to know how it is defined so they can unpack it to get its values. I’ve been using #define’s in my public header to define the keys. That way, I get edit-time compiler checking to ensure I don’t use a bum key. But is there some other, more standard way to declare the interface to a defined dictionary so that other objects will get compile errors if they try to use undefined keys?
Share
Better than
#defineis to use constantNSStrings. In your header:(That’s a constant pointer to an
NSString.) And in your implementation:This is how the frameworks export constant strings. This won’t stop the use of invalid keys, nothing will really do that (it’s C, you can bypass anything), but it raises the bar higher.