From dfba974572c13d7e1e3c8f9507919e626f6782a1 Mon Sep 17 00:00:00 2001 From: Daniel Stolzenberg Date: Wed, 27 Oct 2010 12:35:50 +0200 Subject: [PATCH] enabled subclasses of CPSet to use CPObjects "addObserver:/removeObserver:" methods without throwing exception --- Foundation/CPSet+KVO.j | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Foundation/CPSet+KVO.j b/Foundation/CPSet+KVO.j index d24f11f59..86496c20c 100644 --- a/Foundation/CPSet+KVO.j +++ b/Foundation/CPSet+KVO.j @@ -529,12 +529,18 @@ kvoOperators["sum"] = function sumOperator(self, _cmd, param) - (void)addObserver:(id)observer forKeyPath:(CPString)aKeyPath options:(unsigned)options context:(id)context { - [CPException raise:@"CPKeyValueObservingException" reason:@"CPSet is not key-value observable"]; + if ([isa instanceMethodForSelector:_cmd] === [CPSet instanceMethodForSelector:_cmd]) + [CPException raise:CPInvalidArgumentException reason:"Unsupported method on CPSet"]; + else + [super addObserver:observer forKeyPath:aKeyPath options:options context:context]; } -- (void)removeObserver:(id)observer forKeyPath:(CPString)aKeyPath +-(void)removeObserver:(id)observer forKeyPath:(CPString)aKeyPath { - [CPException raise:@"CPKeyValueObservingException" reason:@"CPSet is not key-value observable"]; + if ([isa instanceMethodForSelector:_cmd] === [CPSet instanceMethodForSelector:_cmd]) + [CPException raise:CPInvalidArgumentException reason:"Unsupported method on CPSet"]; + else + [super removeObserver:observer forKeyPath:aKeyPath]; } @end