From c4370240f8e31c257f038b661a2e171fe346f28b Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 24 Feb 2013 23:43:20 +0000 Subject: [PATCH] Fixed: subclasses of CPMutableArray had broken removeObject:. The `removeObject:` default provided in CPMutableArray would not work in subclasses because it relied on the class having a .length property. --- Foundation/CPArray/CPMutableArray.j | 4 ++-- Tests/Foundation/CPMutableArrayTest.j | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index a1b3538ee..b82eb07ed 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -218,7 +218,7 @@ */ - (void)removeObject:(id)anObject { - [self removeObject:anObject inRange:CPMakeRange(0, self.length)]; + [self removeObject:anObject inRange:CPMakeRange(0, [self count])]; } /*! @@ -233,7 +233,7 @@ while ((index = [self indexOfObject:anObject inRange:aRange]) != CPNotFound) { [self removeObjectAtIndex:index]; - aRange = CPIntersectionRange(CPMakeRange(index, self.length - index), aRange); + aRange = CPIntersectionRange(CPMakeRange(index, [self count] - index), aRange); } } diff --git a/Tests/Foundation/CPMutableArrayTest.j b/Tests/Foundation/CPMutableArrayTest.j index 1633f9fc1..3164350cc 100644 --- a/Tests/Foundation/CPMutableArrayTest.j +++ b/Tests/Foundation/CPMutableArrayTest.j @@ -92,6 +92,17 @@ }]; } +- (void)test_removeObject_ +{ + var arrayClass = [[self class] arrayClass], + a = [CPDate distantFuture], + b = [a copy], + c = [CPDate distantPast], + array = [arrayClass arrayWithObjects:a, b, a, c, b]; + + [array removeObject:a]; + [self assert:array equals:[arrayClass arrayWithObjects:c]]; +} - (void)test_removeObjectsAtIndexes_ { var arrayClass = [[self class] arrayClass],