objective c - Should I Use self Keyword (Properties) In The Implementation? -


O people, I believe that I understand the properties for the most part. My question is, if I have a property for a frequency variable, and I am installing or retrieving it in the implementation file by a method, then I would like to call me self.myProperty or just MyProperty ? I either do one thing, but I have seen mixed sects, sometimes the code gets direct access through the property and directly at other times.

Is there any technical reason to do this? Is this just a conference / personal preference? And I am not referring to examples where the parameter name of a method collide with the name of the present name, which can be a reason to use the property ( at least, in other languages, Do not know about a ). I believe that when someone uses the property within the implementation, they want to take advantage of the method in which they declare the property ( i.e. nonatomic, retain ), for example, in a method Can also:

  self.myProperty = [someObject someAutoReleasedObject]; Instead of  

:

  myProperty = [[someObject someAutoReleasedObject] retained];  

Is this the reason? So are there some such situations where it would be good to use the property?

I'm new to Objective-C, and this is one of the few things that have confused me. So far I have passed this example directly to the extremes, going through the property and sending a call / message / sends and adds unnecessary overhead. I am pretty sure that I am wrong with it, but if the difference in the overhead is very negligible (if none is there), then why should it be added, when anyone can use the straight variable?

Thank you! I am pretty sure that I am wrong in my thinking, that is why I am asking here, to know the truth. I appreciate any responses :)

First of all, you can use satellites or gesters to enter or Apple.com should not do according to Delok (and for good reasons).

In addition, if you have one, you should usually use the setter to set the Variator.

Usually I do not bother using Gates to reach ivar from within the implementation, but there are times when it is necessary. In particular, if you expect that the recipient can do some caselation or check, or if you want to allow sub-classes to override the behavior.

Of course, the use of the recipient in the implementation is more general and safe, but it is generally useless and useless to make your choice.

It is important to use setter because it provides an operator to follow the change of the other code (key value overview), as well as the opportunity to override the sub-sections setter and any Other adjustments are required.

However one thing which I highly recommend is to use a different name for your eyewater and your property. The general convention is an underscore prefix ( _ ), though I Personally using i _ as prefix to avoid any confusion with the personal use of the apple. In this way you can not use it incorrectly:

  self.name // used property i_name // use ivar self.i_name // syntax error name // Syntax error  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -