On 24 Nov 2012, at 09:55, Roland King <r...@rols.org> 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 (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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com