Are there side-effects to calling a custom getter with dot notation?
I had been using a synthesized getter in Objective-C via the dot notation, i.e.
tree.fruitnumber
returned the number of fruits in tree. I had to customize the getter (for reasons not pertinent to this question). I wrote it as
-(int) fruitnumber
{
//climb into tree and hand count fruits. Get n;
return n;
}
Suprisingly, the dotted getter still works. Is this legit, or there is a nasty bug (which will infect all my fruits down the road (to the market?)).
Dot notation is really just syntactic-sugar for bracket notation. So both messages are the same:
The nice thing is, you can
@synthesizeyour properties and the setter/getter methods will be built for you (depending on your property options, of course) but you can write your own instead and they will be used.In the case where you are providing your own setters/getters, you can alternatively use the
@dynamic propertyNameline instead of@synthesizeto tell the compiler these are being provided by you.