Is using “self” ever necessary in Objective-C or maybe just a good practice? I have gone from using it all the time to not using it at all and I don’t seem to really notice any difference. Isn’t it just implied anyway?
Share
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.
selfis necessary if you wish for an object to send messages to, well, itself. It is also occasionally beneficial to access properties through getters/setters, in which case you’ll also need to useself, as inself.propertynameorself.propertyname = value. (These are not equivalent topropertynameorpropertyname = value.