Re: Properties: A question of style
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