Merge pull request #1630 from slevenbits/cparray-fix

Fix CPArray should throw an exception when observer is added/removed.
This commit is contained in:
Alexander Ljungberg committed 2012-07-23 15:34:38 +02:00
commit d0b152c638
1 file changed
+28
+28
View File
@@ -514,6 +514,31 @@
@implementation CPArray (KeyValueObserving)
/*!
Raises an exception.
CPArray objects are not observable, so this method raises an exception when invoked on an CPArray object.
Instead of observing a array, observe the ordered to-many relationship for which the array is the collection of related objects.
*/
- (void)addObserver:(id)anObserver forKeyPath:(CPString)aKeyPath options:(CPKeyValueObservingOptions)anOptions context:(id)aContext
{
[CPException raise:CPInvalidArgumentException reason:"[CPArray " + CPStringFromSelector(_cmd) + "] is not supported. Key path: " + aKeyPath];
}
/*!
Raises an exception.
CPArray objects are not observable, so this method raises an exception when invoked on an CPArray object.
Instead of observing a array, observe the ordered to-many relationship for which the array is the collection of related objects.
*/
- (void)removeObserver:(id)anObserver forKeyPath:(CPString)aKeyPath
{
[CPException raise:CPInvalidArgumentException reason:"[CPArray " + CPStringFromSelector(_cmd) + "] is not supported. Key path: " + aKeyPath];
}
/*!
Registers an observer to receive key value observer notifications for the specified key-path relative to the objects at the indexes.
*/
- (void)addObserver:(id)anObserver toObjectsAtIndexes:(CPIndexSet)indexes forKeyPath:(CPString)aKeyPath options:(unsigned)options context:(id)context
{
var index = [indexes firstIndex];
@@ -526,6 +551,9 @@
}
}
/*!
Removes anObserver from all key value observer notifications associated with the specified keyPath relative to the array’s objects at indexes.
*/
- (void)removeObserver:(id)anObserver fromObjectsAtIndexes:(CPIndexSet)indexes forKeyPath:(CPString)aKeyPath
{
var index = [indexes firstIndex];