So I am reading the new ObjC 2.0 docs:
http://tinyurl.com/yvfz2s
And come across
And am confused.
If I do NOT write any setter/getter methods for the properties, can I just access them using dot notation? And if so, does the set/get code become automagically generated at compile time?
Or do I still write the set/get code, and the dot notation then defaults to using those methods, except that I can just type less (i.e., just the dot notation, rather than actually call the get/set methods)?
http://tinyurl.com/yvfz2s
And come across
Accessing Properties
Using the dot syntax, you can access a property using the same pattern as accessing structure elements.
MyClass *myInstance = [[MyClass alloc] init];
myInstance.value = @"New value";
NSLog(@"myInstance value: %@", myInstance.value);
The dot syntax is purely syntactic sugarit is transformed by the compiler into invocation of accessor methods (so you are not actually accessing an instance variable directly). The code example above is exactly equivalent to the following:
MyClass *myInstance = [[MyClass alloc] init];
[myInstance setValue"New value"];
NSLog(@"myInstance value: %@", [myInstance value]);
And am confused.
If I do NOT write any setter/getter methods for the properties, can I just access them using dot notation? And if so, does the set/get code become automagically generated at compile time?
Or do I still write the set/get code, and the dot notation then defaults to using those methods, except that I can just type less (i.e., just the dot notation, rather than actually call the get/set methods)?