CPObjectCPArray
@implementation CPArray : CPObject
A mutable array class backed by a JavaScript Array.
There is also a CPMutableArray
class,
but it is just a child class of this class with an
empty implementation. All mutable functionality is
implemented directly in CPArray
.
Method Summary | |
---|---|
+(id) | alloc Returns a new uninitialized CPArray . |
+(id) | array Returns a new initialized CPArray . |
+(id) | arrayWithArray:(CPArray)anArray Creates a new array containing the objects in anArray . |
+(CPArray) | arrayWithCapacity:(unsigned)aCapacity Creates an array able to store at least aCapacity
items. |
+(id) | arrayWithObject:(id)anObject Creates a new array with anObject in it. |
+(id) | arrayWithObjects:(id)anObject,... Creates a new CPArray containing all the objects passed as arguments to the method. |
+(id) | arrayWithObjects:(id)objects count:(unsigned)aCount Creates a CPArray from a JavaScript array of objects. |
-(id) | init Initializes the CPArray . |
-(id) | initWithArray:(CPArray)anArray Creates a new CPArray from anArray . |
-(id) | initWithArray:(CPArray)anArray copyItems:(BOOL)copyItems Initializes a the array with the contents of anArray
and optionally performs a deep copy of the objects based on copyItems . |
-(id) | initWithCapacity:(unsigned)aCapacity Initializes an array able to store at least aCapacity items. |
-(id) | initWithCoder:(CPCoder)aCoder |
-(id) | initWithObjects:(Array)anObject,... initializes. |
-(id) | initWithObjects:(id)objects count:(unsigned)aCount Initializes the array with a JavaScript array of objects. |
-(void) | addObject:(id)anObject Adds anObject to the end of the array. |
-(void) | addObjectsFromArray:(CPArray)anArray Adds the objects in anArray to the receiver array. |
-(CPArray) | arrayByAddingObject:(id)anObject Returns a copy of this array plus anObject inside the copy. |
-(CPArray) | arrayByAddingObjectsFromArray:(CPArray)anArray Returns a new array which is the concatenation of self and otherArray (in this precise order). |
-(CPString) | componentsJoinedByString:(CPString)aString Returns a string formed by concatenating the objects in the receiver, with the specified separator string inserted between each part. |
-(BOOL) | containsObject:(id)anObject Returns YES if the array contains anObject . |
-(id) | copy Makes a copy of the receiver. |
-(int) | count Returns the number of elements in the array. |
-(CPString) | description Returns a human readable description of this array and it's elements. |
-(void) | encodeWithCoder:(CPCoder)aCoder |
-(void) | exchangeObjectAtIndex:(unsigned)anIndex withObjectAtIndex:(unsigned)otherIndex Swaps the elements at the two specified indices. |
-(id) | firstObjectCommonWithArray:(CPArray)anArray Returns the first object found in the receiver (starting at index 0) which is present in the otherArray as determined by using the -containsObject: method. |
-(unsigned) | hash Returns a hash of the CPArray . |
-(int) | indexOfObject:(id)anObject Returns the index of anObject in this array. |
-(int) | indexOfObjectIdenticalTo:(id)anObject Returns the index of anObject in the array. |
-(int) | indexOfObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange Returns the index of anObject in the array
within aRange . |
-(int) | indexOfObject:(id)anObject inRange:(CPRange)aRange Returns the index of anObject in the array
within aRange . |
-(void) | insertObject:(id)anObject atIndex:(int)anIndex Inserts an object into the receiver at the specified location. |
-(void) | insertObjects:(CPArray)objects atIndexes:(CPIndexSet)anIndexSet Inserts the objects in the provided array into the receiver at the indexes specified. |
-(BOOL) | isEqualToArray:(id)anArray Returns true if anArray contains exactly the same objects as the reciever. |
-(id) | lastObject Returns the last object in the array. |
-(void) | makeObjectsPerformSelector:(SEL)aSelector Sends each element in the array a message. |
-(void) | makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject Sends each element in the array a message with an argument. |
-(id) | objectAtIndex:(int)anIndex Returns the object at index anIndex . |
-(CPEnumerator) | objectEnumerator Returns an enumerator describing the array sequentially from the first to the last element. |
-(CPArray) | objectsAtIndexes:(CPIndexSet)indexes Returns the objects at indexes in a new CPArray . |
-(CPArray) | pathsMatchingExtensions:(CPArray)filterTypes Returns a new array subset formed by selecting the elements that have filename extensions from filterTypes . |
-(void) | removeAllObjects Removes all objects from this array. |
-(void) | removeLastObject Removes the last object from the array. |
-(void) | removeObject:(id)anObject Removes all entries of anObject from the array. |
-(void) | removeObjectAtIndex:(int)anIndex Removes the object at anIndex . |
-(void) | removeObjectIdenticalTo:(id)anObject Remove the first instance of anObject from the array. |
-(void) | removeObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange Remove the first instance of anObject from the array,
within the range specified by aRange . |
-(void) | removeObject:(id)anObject inRange:(CPRange)aRange Removes all entries of anObject from the array, in the range specified by aRange . |
-(void) | removeObjectsAtIndexes:(CPIndexSet)anIndexSet Removes the objects at the indices specified by CPIndexSet . |
-(void) | removeObjectsInArray:(CPArray)anArray Remove the objects in anArray from the receiver array. |
-(void) | removeObjectsInRange:(CPRange)aRange Removes all the objects in the specified range from the receiver. |
-(void) | replaceObjectAtIndex:(int)anIndex withObject:(id)anObject Replaces the element at anIndex with anObject . |
-(void) | replaceObjectsAtIndexes:(CPIndexSet)anIndexSet withObjects:(CPArray)objects Replace the elements at the indices specified by anIndexSet with
the objects in objects . |
-(void) | replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray Replaces some of the receiver's objects with the objects from anArray . |
-(void) | replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray range:(CPRange)otherRange Replaces some of the receiver's objects with objects from anArray . |
-(CPEnumerator) | reverseObjectEnumerator Returns an enumerator describing the array sequentially from the last to the first element. |
-(void) | setArray:(CPArray)anArray Sets the contents of the receiver to be identical to the contents of anArray . |
-(void) | setValue:(id)aValue forKey:(CPString)aKey Sets the key-value for each element in the array. |
-(CPArray) | sortUsingDescriptors:(CPArray)descriptors |
-(void) | sortUsingFunction:(Function)aFunction context:(id)aContext Sorts the receiver array using a JavaScript function as a comparator, and a specified context. |
-(void) | sortUsingSelector:(SEL)aSelector Sorts the receiver array using an Objective-J method as a comparator. |
-(CPArray) | sortedArrayUsingDescriptors:(CPArray)descriptors Not yet described. |
-(CPArray) | sortedArrayUsingFunction:(Function)aFunction context:(id)aContext Returns an array in which the objects are ordered according to a sort with aFunction . |
-(CPArray) | sortedArrayUsingSelector:(SEL)aSelector Returns a new array in which the objects are ordered according to a sort with aSelector . |
-(CPArray) | subarrayWithRange:(CPRange)aRange Returns a subarray of the receiver containing the objects found in the specified range aRange . |
-(CPArray) | valueForKey:(CPString)aKey Returns the value for aKey from each element in the array. |
Method Detail |
---|
+(id)alloc
CPArray
.+(id)array
CPArray
.+(id)arrayWithArray:(CPArray)anArray
anArray
.anArray
- Objects in this array will be added to the new arrayCPArray
of the provided objects
+(CPArray)arrayWithCapacity:(unsigned)aCapacity
aCapacity
items. Because CPArray
is backed by JavaScript arrays,
this method ends up simply returning a regular array.aCapacity
+(id)arrayWithObject:(id)anObject
anObject
in it.anObject
- the object to be added to the arrayCPArray
containing a single object
+(id)arrayWithObjects:(id)anObject,...
CPArray
containing all the objects passed as arguments to the method.anObject,...
CPArray
containing the argument objects
+(id)arrayWithObjects:(id)objects count:(unsigned)aCount
CPArray
from a JavaScript array of objects.objects
- the JavaScript ArrayaCount
- the number of objects in the JS ArrayCPArray
containing the specified objects
-(id)init
CPArray
.-(id)initWithArray:(CPArray)anArray
CPArray
from anArray
.anArray
- objects in this array will be added to the new arrayCPArray
containing the objects of anArray
-(id)initWithArray:(CPArray)anArray copyItems:(BOOL)copyItems
anArray
and optionally performs a deep copy of the objects based on copyItems
.anArray
- the array to copy the data fromcopyItems
- if YES
, each object will be copied by having a copy
message sent to it, and the
returned object will be added to the receiver. Otherwise, no copying will be performed.-(id)initWithCapacity:(unsigned)aCapacity
aCapacity
items. Because CPArray
is backed by JavaScript arrays, this method ends up simply returning a regular array.aCapacity
-(id)initWithCoder:(CPCoder)aCoder
aCoder
-(id)initWithObjects:(Array)anObject,...
anObject,...
-(id)initWithObjects:(id)objects count:(unsigned)aCount
objects
- the array of objects to add to the receiveraCount
- the number of objects in objects
CPArray
-(void)addObject:(id)anObject
anObject
to the end of the array.anObject
- the object to add to the array-(void)addObjectsFromArray:(CPArray)anArray
anArray
to the receiver array.anArray
- the array of objects to add to the end of the receiver-(CPArray)arrayByAddingObject:(id)anObject
anObject
inside the copy.anObject
- the object to be added to the array copyCPInvalidArgumentException
- if anObject
is nil
-(CPArray)arrayByAddingObjectsFromArray:(CPArray)anArray
self
and otherArray (in this precise order).anArray
- the array that will be concatenated to the receiver's copy-(CPString)componentsJoinedByString:(CPString)aString
description
of that object will be used, otherwise the default JavaScript representation will be used.aString
- the separator that will separate each object string-(BOOL)containsObject:(id)anObject
YES
if the array contains anObject
. Otherwise, it returns NO
.anObject
- the method checks if this object is already in the array-(id)copy
CPArray
copy
-(int)count
-(CPString)description
-(void)encodeWithCoder:(CPCoder)aCoder
aCoder
-(void)exchangeObjectAtIndex:(unsigned)anIndex withObjectAtIndex:(unsigned)otherIndex
anIndex
- the first index to swap fromotherIndex
- the second index to swap from-(id)firstObjectCommonWithArray:(CPArray)anArray
otherArray
as determined by using the -containsObject:
method.anArray
nil
if no common object was found.
-(unsigned)hash
CPArray
.-(int)indexOfObject:(id)anObject
anObject
in this array.
If the object is nil
or not in the array,
returns CPNotFound
. It first attempts to find
a match using isEqual:
, then ==
.anObject
- the object to search for-(int)indexOfObjectIdenticalTo:(id)anObject
anObject
in the array. The test for equality is done using only ==
.anObject
- the object to search forCPNotFound
if the object is not in the array.
-(int)indexOfObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange
anObject
in the array
within aRange
. The test for equality is
done using only ==
.anObject
- the object to search foraRange
- the range to search withinCPNotFound
if it was not found.
-(int)indexOfObject:(id)anObject inRange:(CPRange)aRange
anObject
in the array
within aRange
. It first attempts to find
a match using isEqual:
, then ==
.anObject
- the object to search foraRange
- the range to search withinCPNotFound
if it was not found.
-(void)insertObject:(id)anObject atIndex:(int)anIndex
anObject
- the object to insert into the arrayanIndex
- the location to insert anObject
at-(void)insertObjects:(CPArray)objects atIndexes:(CPIndexSet)anIndexSet
objects
- the objects to add to this arrayanIndexSet
- the indices for the objects-(BOOL)isEqualToArray:(id)anArray
anArray
-(id)lastObject
nil
/-(void)makeObjectsPerformSelector:(SEL)aSelector
aSelector
- the selector of the message to sendCPInvalidArgumentException
- if aSelector
is nil
-(void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject
aSelector
- the selector of the message to sendanObject
- the first argument of the messageCPInvalidArgumentException
- if aSelector
is nil
-(id)objectAtIndex:(int)anIndex
anIndex
.anIndex
CPRangeException
- if anIndex
is out of bounds-(CPEnumerator)objectEnumerator
-(CPArray)objectsAtIndexes:(CPIndexSet)indexes
indexes
in a new CPArray
.indexes
- the set of indicesCPRangeException
- if any of the indices is greater than or equal to the length of the array-(CPArray)pathsMatchingExtensions:(CPArray)filterTypes
filterTypes
. Only elements
that are of type CPString
are candidates for inclusion in the returned array.filterTypes
- an array of CPString
objects that contain file extensions (without the '.')-(void)removeAllObjects
-(void)removeLastObject
-(void)removeObject:(id)anObject
anObject
from the array.anObject
- the object whose entries are to be removed-(void)removeObjectAtIndex:(int)anIndex
anIndex
.anIndex
- the location of the element to be removed-(void)removeObjectIdenticalTo:(id)anObject
anObject
from the array.
The search for the object is done using ==
.anObject
- the object to remove-(void)removeObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange
anObject
from the array,
within the range specified by aRange
.
The search for the object is done using ==
.anObject
- the object to removeaRange
- the range in the array to search for the object-(void)removeObject:(id)anObject inRange:(CPRange)aRange
anObject
from the array, in the range specified by aRange
.anObject
- the object to removeaRange
- the range to search in the receiver for the object-(void)removeObjectsAtIndexes:(CPIndexSet)anIndexSet
CPIndexSet
.anIndexSet
- the indices of the elements to be removed from the array-(void)removeObjectsInArray:(CPArray)anArray
anArray
from the receiver array.anArray
- the array of objects to remove from the receiver-(void)removeObjectsInRange:(CPRange)aRange
aRange
- the range of objects to remove-(void)replaceObjectAtIndex:(int)anIndex withObject:(id)anObject
anIndex
with anObject
.
The current element at position anIndex
will be removed from the array.anIndex
- the position in the array to place anObject
anObject
-(void)replaceObjectsAtIndexes:(CPIndexSet)anIndexSet withObjects:(CPArray)objects
anIndexSet
with
the objects in objects
.anIndexSet
- the set of indices to array positions that will be replacedobjects
- the array of objects to place in the specified indices-(void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray
anArray
. Specifically, the elements of the
receiver in the range specified by aRange
.aRange
- the range of elements to be replaced in the receiveranArray
- the array to retrieve objects for placement into the receiver-(void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray range:(CPRange)otherRange
anArray
. Specifically, the elements of the
receiver in the range specified by aRange
,
with the elements of anArray
in the range specified by otherRange
.aRange
- the range of elements to be replaced in the receiveranArray
- the array to retrieve objects for placement into the receiverotherRange
- the range of objects in anArray
to pull from for placement into the receiver-(CPEnumerator)reverseObjectEnumerator
-(void)setArray:(CPArray)anArray
anArray
.anArray
- the array of objects used to replace the receiver's objects-(void)setValue:(id)aValue forKey:(CPString)aKey
aValue
- the value for the codingaKey
- the key for the coding-(CPArray)sortUsingDescriptors:(CPArray)descriptors
descriptors
-(void)sortUsingFunction:(Function)aFunction context:(id)aContext
aFunction
- a JavaScript function that will be called to compare objectsaContext
- an object that will be passed to aFunction
with comparison-(void)sortUsingSelector:(SEL)aSelector
aSelector
- the selector for the method to call for comparison-(CPArray)sortedArrayUsingDescriptors:(CPArray)descriptors
descriptors
-(CPArray)sortedArrayUsingFunction:(Function)aFunction context:(id)aContext
aFunction
. This invokes
-sortUsingFunction:context
.aFunction
- a JavaScript 'Function' type that compares objectsaContext
- context information-(CPArray)sortedArrayUsingSelector:(SEL)aSelector
aSelector
.aSelector
- the selector that will perform object comparisons-(CPArray)subarrayWithRange:(CPRange)aRange
aRange
.aRange
- the range of objects to be copied into the subarrayCPRangeException
- if the specified range exceeds the bounds of the array-(CPArray)valueForKey:(CPString)aKey
aKey
from each element in the array.aKey
- the key to return the value forCreated on Sat Sep 13 14:15:43 PDT 2008