I want to define a constant in my .m file. I can see two options here:
static NSString *const kMyLabel = @"myLabel";
#define kMyLabel @"myLabel"
Which one is the best? Is there any issues with using static here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only difference is that you can take the address of the variable, while you cannot take the address of a constant string expression (which is what the macro reduces to). I prefer to avoid
#defines when possible, so I’d go with the former, but that’s just a matter of style.