May 2011
Beginner
834 pages
25h 19m
English
A property (see Chapter 5) is syntactic sugar for calling an accessor by using dot-notation. An object does not have a property unless its class (or that class’s superclass, of course) declares it. For instance, in a earlier example we had an object with an NSMutableArray instance variable and a setter, which we called like this:
[self setTheData: d];
If this object’s class code declares a property theData, we could instead say:
self.theData = d;
The effect would be exactly the same, because setting a property is just a shorthand for calling the setter. Similarly, suppose we were to say this:
NSMutableArray* arr = self.theData;
That is exactly the same as calling the getter.
Properties offer certain advantages that accessors, of themselves, do not:
Read now
Unlock full access