Which is better practice; manipulating properties with accessors by @property or self.property?
Which is better practice; manipulating properties with accessors by @property or self.property ?
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.
If you are just using straight accessors, then stick to
@property(unless you come from Python and are turned off by the@sigil hehe) otherwise:It’s entirely up to you. But
self.propertycan be useful in some circumstances where you need to ensure the property is initially set up:Also beware that there is a slight overhead to using
self.propertyover@propertyasself.propertyis a method call.NOTE: The reason i’m using
self.propertyover justpropertyis because the corresponding setter methodproperty=requires an explicit receiver:self.property=, so I choose to use the explicit receiver with both.