On Sep 19, 2010, at 9:52 PM, Jim Thomason wrote:
> So basically, I get a language built-in version of a macro, and an
> option to use a new syntax that I'm not interested in anyway.
> 
> Is there something else I'm not seeing or some other utility to them
> that I don't yet understand?


 One point nobody mentioned so far: You can use different names for your public 
property (e.g. an IBOutlet) and your internal storage (i.e. the instance 
variable). I like to avoid name collisions between local variables and instance 
variables by using an m prefix on instance variables. Using @synthesize 
cancelButton = mCancelButton;, I can do that.

 Instead of declaring the instance variable as an IBOutlet, I can now declare

@property (retain) IBOutlet NSButton*    cancelButton;

 and IB will call setCancelButton:, not setMCancelButton:, which wasn't 
possible without properties.

Also, if you are implementing a framework class that is subclassed by the apps 
linking to your framework, you can keep it binary-stable and avoid "fragile 
base class"-problems by only having one real ivar that points to a struct 
containing the actual ivars. Again, you wouldn't be able to do IBOutlets in 
that case if you didn't have property declarations, even though you'll end up 
writing the getter and setter manually.

 Apart from that, let me emphasize what others have said:

 It writes getters/setters for you. Every line of code you don't have to write 
is a line of code you don't have to debug

 And finally: properties contain additional mark-up on a method. A future 
version of the Clang Static Analyzer could detect violations of thread-safety 
in your code and similar issues with help from property declarations.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to