Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Classes can have instance variables (ivars). These are in the first section, and are only visible to code in that class, not any outside code. I like to prefix them with an underscore to show their internal-ness. In low level terms, the ivars are added as an additional member to the struct that the class you are creating uses internally.</p> <p>The second declaration, @property, is a declared property. It is not required (except when you are using @synthesize), but it helps other programmers (and the compiler!) know that you are dealing with a property, and not just two methods <code>-setAVar</code> and <code>-aVar</code>, which is the alternative way of doing this.</p> <p>Thirdly, the @synthesize actually creates the methods to set and access the property from outside the class. You can replace this with your own setter and getter methods, but only do that if you need to, as the built-in ones have some features that you would otherwise have to code yourself. In fact, using the <code>@synthesize aVar = _someVariable;</code> syntax, you can have your property actually reference a differently named instance variable!</p> <p>Short version: The @property is just a hint to the compiler and other programmers that you are making a property and not just getter/setter methods. The instance variables are internal to the class, and otherwise cannot be normally accessed from outside it. The @synthesize just creates simple getters and setters for you, to go with your @property, but you can also just code those getters and setters yourself, like any other method.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload