I understand using constants for your names in a NSDictionary to prevent typos (myName will auto complete vs @"myName" won't).
i'm working with a medium size dictionaries right now and a couple of times, i've misstyped key names and had to spend some time tracking down where i miss spelled a word.
i'm wondering, do you consider it worth while to set up a constants naming scheme?
Yes, but I'd advise defining proper string constants rather than #defines for your strings because string constants are type-safe and every reference will use the same actual string object, which improves the performance of using isEqualToString:
to compare them.
To define a private string constant you can put this in your .m file:
static NSString *const MyConstant = @"MyConstant";
To make it public, you can either put this in your .h file instead, or you can split the definition by putting this in your .h:
extern NSString *const MyConstant;
And this in your .m file:
NSString *const MyConstant = @"MyConstant";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With