• 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: overriding a method with NSObject's version
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: overriding a method with NSObject's version


  • Subject: Re: overriding a method with NSObject's version
  • From: "email@hidden" <email@hidden>
  • Date: Sat, 24 Nov 2012 14:23:33 +0000


On 24 Nov 2012, at 09:55, Roland King <email@hidden> wrote:

> I have a fairly well-used and oft-subclassed class which overrides valueForKey: and setValue:ForKey: to behave like the NSDictionary versions, because this class looks much like an NSDictionary. I have a subclass of that which wants to do 'normal' KVO, and so I need valueForKey: and setValueForKey: to return to the default NSObject version.
>
> I could use composition but that's a lot of boilerplate to re-expose the properties of the composed class and I really did want it to be a subclass. I could code up a custom valueForKey: which does the right thing, but that's fragile if I add more properties or subclass again. So I want to actually make the implementation of those two methods in my subclass use the NSObject implementation.
>
>

Would something like the following be worth considering:

Class A uses custom valueForKey.
SubClass A1 needs the super implementation.

A:

+ (BOOL)useCustomKVO
{
	return YES;
}

- (id)valueForKey:(NSString *)key
{
	if (!self.class.useCustomKVO) {
		return [super valueForKey:key];
	}

	// do custom KVO
}

A1 : A:

+ (BOOL)useCustomKVO
{
	return NO;
}

Regards

Jonathan Mitchell
Mugginsoft LLP







_______________________________________________

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: overriding a method with NSObject's version
      • From: Roland King <email@hidden>
References: 
 >overriding a method with NSObject's version (From: Roland King <email@hidden>)

  • Prev by Date: Re: NSComparisonPredicate vs. predicateWithFormat
  • Next by Date: Re: overriding a method with NSObject's version
  • Previous by thread: overriding a method with NSObject's version
  • Next by thread: Re: overriding a method with NSObject's version
  • Index(es):
    • Date
    • Thread