On Nov 11, 2009, at 11:52 AM, Christian Ziegler wrote: > In order to reuse code I find it often very handy to write little "getters" > which don't get their return value from an ivar but compute it somehow. I > believe this is called derived property since it derives its value from other > properties. My question is, what is the best style implementing such derived > properties. With dot-notation in mind, I think the options are: > > 1. Only write the "getter"-method, no property, no sythesize, DON'T use > dot-notation > 2. Only write the "getter"-method, no property, no sythesize, DO use > dot-notation > 3. Write "getter"-method, write property (readonly, to justify dot-notation), > sythesize > > A basic question here is, for any method which might as well be a property > and of course doesn't have any parameters, is it ok to use dot-notation or > should'nt you do that. > > Simple example: > > - (BOOL)itemsSelected { > return [myTableView selectedRow] != -1; > }
4. Write a getter method, @property(readonly), and no @synthesize. Use dot notation if you like. There's no need to @synthesize since you are providing the entire property implementation (the getter method) yourself. One reason to make it a proper @property is that Xcode's autocompletion of dot notation only looks at @properties, not methods. So `obj.i` will autocomplete to `obj.itemsSelected` only if there is an @property itemsSelected. -- Greg Parker gpar...@apple.com Runtime Wrangler _______________________________________________ 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