• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Derived properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Derived properties


  • Subject: Re: Derived properties
  • From: Greg Parker <email@hidden>
  • Date: Wed, 11 Nov 2009 12:31:24 -0800

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     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Derived properties
      • From: Quincey Morris <email@hidden>
References: 
 >Derived properties (From: Christian Ziegler <email@hidden>)

  • Prev by Date: -[NSString stringWithCString:encoding:] memory management question
  • Next by Date: Re: Create and save a NSPersistentDocument from scratch
  • Previous by thread: Derived properties
  • Next by thread: Re: Derived properties
  • Index(es):
    • Date
    • Thread