Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -125,14 +125,16 @@ * \return The last object of the OFArray or nil */ - (id)lastObject; - addObject: (OFObject*)obj; +- addObject: (OFObject*)obj + atIndex: (size_t)index; - removeObject: (id)obj; - removeObjectIdenticalTo: (id)obj; - removeObjectAtIndex: (size_t)index; - removeNObjects: (size_t)nobjects; - removeNObjects: (size_t)nobjects atIndex: (size_t)index; @end #import "OFMutableArray.h" Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -274,10 +274,17 @@ [super dealloc]; } - addObject: (OFObject*)obj +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} + +- addObject: (OFObject*)obj + atIndex: (size_t)index { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -15,16 +15,25 @@ * The OFMutableArray class provides a class for storing, adding and removing * objects in an array. */ @interface OFMutableArray: OFArray {} /** - * Adds an object to the OFDataArray. + * Adds an object to the OFArray. * * \param obj An object to add */ - addObject: (OFObject*)obj; +/** + * Adds an object to the OFArray at the specified index. + * + * \param obj An object to add + * \param index The index where the object should be added + */ +- addObject: (OFObject*)obj + atIndex: (size_t)index; + /** * Removes the first object equivalent to the specified object. * * \param obj The object to remove */ @@ -43,11 +52,11 @@ * \param index The index of the object to remove */ - removeObjectAtIndex: (size_t)index; /** - * Removes the specified amount of objects from the end of the OFDataArray. + * Removes the specified amount of objects from the end of the OFArray. * * \param nobjects The number of objects to remove */ - removeNObjects: (size_t)nobjects; Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -36,10 +36,20 @@ - addObject: (OFObject*)obj { [array addItem: &obj]; [obj retain]; + return self; +} + +- addObject: (OFObject*)obj + atIndex: (size_t)index +{ + [array addItem: &obj + atIndex: index]; + [obj retain]; + return self; } - removeObject: (id)obj { Index: tests/OFArray.m ================================================================== --- tests/OFArray.m +++ tests/OFArray.m @@ -38,11 +38,14 @@ (a[1] = [OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) TEST(@"+[arrayWithCArray:]", (a[2] = [OFArray arrayWithCArray: c_ary])) TEST(@"-[addObject:]", [a[0] addObject: c_ary[0]] && - [a[0] addObject: c_ary[1]] && [a[0] addObject: c_ary[2]]) + [a[0] addObject: c_ary[2]]) + + TEST(@"-[addObject:]", [a[0] addObject: c_ary[1] + atIndex: 1]) TEST(@"-[count]", [a[0] count] == 3 && [a[1] count] == 3 && [a[2] count] == 3) TEST(@"-[isEqual:]", [a[0] isEqual: a[1]] && [a[1] isEqual: a[2]])