I have some strings in my project and I want to put all the strings in a common file say constants.
(1st Approach) In constants.h, I can do :
#define COMMON_STRING @"myString"
OR
(2nd Approach)
In constants.h
extern NSString *const COMMON_STRING;
In constants.m
NSString *const COMMON_STRING = @"myString";
Which approach is better to use and why?or do we have some other better approach for this?
EDIT:
According to that post extern NSString *const COMMON_STRING; is better in terms of memory perspective. But somewhere I have also read that The #define will insert the string into all the occurrences, by that - multiplying the memory usage unless compiler optimizing same constant string occurrences — which is the case.So does it make sense not to use #define?
In the suggested posts one post only defines the structure and other is explaining the comparison but very limited and not what I am expecting.If compiler is optimizing same constant string occurrences then why to use extern NSString *const COMMON_STRING and not #define COMMON_STRING?