Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

linkedlist

macrumors newbie
Original poster
I am slowly working my way through a cocoa tutorial, some questions I have dont appear answered in the book.

Just got to @property and @synthesize - I understand accessors and mutators and realise that this is what they are doing - but am I correct in thinking that if I use this method, all I will ever have is a very simple set and get mechanism?

If I wanted to add anything else to the getter and setter, ie a message logged to the console when a value is set, then I have to explicitly type out the old set and get methods.

There's no way to piggy back extra statements into the 'generated' methods is there?
 
Unfortunately correct. This also means that the various attributes of properties ('atomic', 'copy', 'retain', etc...) are only automatic for @synthesized accessors. You'll need to ensure that the header matches the implementation for your own.
 
The way I do this is through key-value observing. That way you keep the full implementation of @properties but still can do things after a value has changed. It's not as flexible though, so it depends on your situation, but has worked for me.
 
I am slowly working my way through a cocoa tutorial, some questions I have dont appear answered in the book.

Just got to @property and @synthesize - I understand accessors and mutators and realise that this is what they are doing - but am I correct in thinking that if I use this method, all I will ever have is a very simple set and get mechanism?

If I wanted to add anything else to the getter and setter, ie a message logged to the console when a value is set, then I have to explicitly type out the old set and get methods.

There's no way to piggy back extra statements into the 'generated' methods is there?

Nobody forces you to use @synthesize. @synthesize tells the compiler "insert the code for me right here". Just write the _complete_ implementation of the accessor yourself.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.