Go to the previous, next section.

Adding Elements to a Collection

Talk about adding.

Basic Adding

Adding, adding if absent, adding a copy, adding all contents of another collection, adding contents if absent, adding with varargs.

@deftypemethod Collection {} @keyword{-addObject:} newObject @deftypemethodx Collection {} @keyword{-addElement:} (elt)newElement Adds newObject to the receiving collection. Returns self.

@deftypemethod Collection {} @keyword{-addObjectIfAbsent:} newObject @deftypemethodx Collection {} @keyword{-addElementIfAbsent:} (elt)newElement Adds newObject to the receiving collection only if newObject isn't there already. Returns self.

@deftypemethod Collection {} @keyword{-addContentsOf:} (id <Collecting>)newObject Adds all the elements in aCollection to the receiving collection. Returns self.

@deftypemethod Collection {} @keyword{-addContentsOfIfAbsent:} (id <Collecting>)newObject <<Undocumented>> Returns self.

@deftypemethod Collection {} @keyword{-addObjectsCount:} (unsigned)count, ... @deftypemethodx Collection {} @keyword{-addElementsCount:} (unsigned)count, ... <<Undocumented>> Returns self.

Here is an example

id o1 = [[Foo alloc] init];
id o2 = [[Bar alloc] init];
id myArray = [[[Array alloc] init] addObjectsCount: 2, o1, o2];

Keyed Adding

If the collection's contents are accessible by a key, members can be inserted at a specified key. See KeyedCollecting protocol.

@deftypemethod KeyedCollection {} @keyword{-insertObject:} newContentObject @keyword{atKey:} (elt)aKey @deftypemethodx KeyedCollection {} @keyword{-insertElement:} (elt)newContentElement @keyword{atKey:} (elt)aKey <<Undocumented>> returns self.

Indexed Adding

Furthermore, if the collections contents are accessible by an index (an unsigned integer key), members can be appended, prepended. Inserted members push other members down to make room. See IndexedCollecting protocol.

@deftypemethod IndexedCollection {} @keyword{-insertObject:} newObject @keyword{atIndex:} (unsigned)index @deftypemethodx IndexedCollecting {} @keyword{-insertElement:} (elt)newElement @keyword{atIndex:} (unsigned)index <<Undocumented>> returns self.

@deftypemethod IndexedCollection {} @keyword{-insertObject:} newObject @keyword{before:} oldObject @deftypemethodx IndexedCollecting {} @keyword{-insertElement:} (elt)newElement @keyword{before:} oldObject <<Undocumented>> returns self.

@deftypemethod IndexedCollection {} @keyword{-insertObject:} newObject @keyword{after:} oldObject @deftypemethodx IndexedCollecting {} @keyword{-insertElement:} (elt)newElement @keyword{after:} oldObject <<Undocumented>> returns self.

@deftypemethod IndexedCollection {} @keyword{insertContentsOf:} (id <Collecting>)aCollection @keyword{atIndex:} (unsigned)index <<Undocumented>> returns self.

@deftypemethod IndexedCollection {} @keyword{-appendObject:} newObject @deftypemethodx IndexedCollecting {} @keyword{-appendElement:} (elt)newElement @deftypemethodx IndexedCollection {} @keyword{-prependObject:} newObject @deftypemethodx IndexedCollecting {} @keyword{-prependElement:} (elt)newElement <<Undocumented>> returns self.

@deftypemethod IndexedCollection {} @keyword{-appendContentsOf:} (id <Collecting>)aCollection @deftypemethodx IndexedCollection {} @keyword{-prependContentsOf:} (id <Collecting>)aCollection <<Undocumented>> returns self.

<<This section unfinished.>>

Go to the previous, next section.