• 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: Properties: A question of style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Properties: A question of style


  • Subject: Re: Properties: A question of style
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 15 Jun 2016 16:56:10 -0700
  • Feedback-id: 167118m:167118agrif8a:167118saRidlag0n:SMTPCORP

On Jun 15, 2016, at 16:34 , Graham Cox <email@hidden> wrote:
>
> If the property is ‘isFoo’, then in every situation (such as KVO, or using dot syntax) I would be using the keypath “isFoo”, and that’s fine, but it’s inconsistent with other properties that are not readonly, where the underlying property is ‘foo’, but in some code I’d use ‘isFoo’ and other times I’d just use ‘foo’. However, if I try and make that consistent, by having the property ‘foo’ and a custom getter ‘isFoo’, then for a readonly property it seems a bit redundant.

You may be overthinking that. From the documentation, here’s what happens with 'valueForKey:<key>’:

> Default Search Pattern for valueForKey:
>
> When the default implementation of valueForKey: is invoked on a receiver, the following search pattern is used:
>
> 	• Searches the class of the receiver for an accessor method whose name matches the pattern get<Key>, <key>, or is<Key>, in that order.

https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/SearchImplementation.html

That is, if the property is “foo”, it doesn’t matter whether the getter is “foo” or “isFoo”, though the setter needs to be “setFoo:". (If the property is “isFoo”, then the getter and setter must be “isFoo” and “setIsFoo:”.)

_______________________________________________

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


References: 
 >Properties: A question of style (From: Graham Cox <email@hidden>)
 >Re: Properties: A question of style (From: Jens Alfke <email@hidden>)
 >Re: Properties: A question of style (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Properties: A question of style
  • Next by Date: Re: Properties: A question of style
  • Previous by thread: Re: Properties: A question of style
  • Next by thread: Selected value binding in popups
  • Index(es):
    • Date
    • Thread