What is the defference if I called
NSString *theNameToDisplay = _name;
or
NSString *theNameToDisplay = self.name;
I know it might be a silly question but I see both versions used a lot and I don’t spot a difference in the output?
Thanks!
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.
Assume you have in your .m file this line (and don’t have any overriden methods to direct access to _name)
It mean that property
name(self.name) will use variable _name when you try to access it. In this caseself.nameis equal to _nameBut if you have dynamic property for name, something like this :
then there is a difference.
self.namewill always return 1234, but _name can be not equal to this value.Example:
Result: