Up
Authors
- Andrew Kachites McCallum (
mccallum@gnu.ai.mit.edu
)
-
- Adam Fedor (
fedor@boulder.colorado.edu
)
-
- Richard Frith-Macdonald (
richard@brainstorm.co.uk
)
-
Date: 2006-03-08 04:28:59 -0700 (Wed, 08 Mar 2006)
Copyright: (C) 1995, 1996, 1998 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSArray.h
- Conforms to:
- NSCoding
- NSCopying
- NSMutableCopying
Availability: OpenStep
A simple, low overhead, ordered container for objects. All the objects in the container are retained by it. The container may not contain
nil
(though it may contain
[NSNull +null]
).
Method summary
+ (id)
array;
Availability: OpenStep
Returns an empty autoreleased array.
+ (id)
arrayWithArray: (
NSArray*)array;
Availability: OpenStep
Returns a new autoreleased NSArray instance containing all the objects from array , in the same order as the original.
+ (id)
arrayWithContentsOfFile: (
NSString*)file;
Availability: OpenStep
+ (id)
arrayWithContentsOfURL: (
NSURL*)aURL;
Availability: MacOS-X 10.0.0
+ (id)
arrayWithObject: (id)anObject;
Availability: OpenStep
Returns an autoreleased array containing anObject.
+ (id)
arrayWithObjects: (id)firstObject
,...;
Availability: OpenStep
Returns an autoreleased array containing the list of objects, preserving order.
+ (id)
arrayWithObjects: (id*)objects
count: (unsigned)count;
Availability: OpenStep
Returns an autoreleased array containing the specified objects, preserving order.
- (
NSArray*)
arrayByAddingObject: (id)anObject;
Availability: OpenStep
Returns an autoreleased array formed from the contents of the receiver and adding anObject as the last item.
- (
NSArray*)
arrayByAddingObjectsFromArray: (
NSArray*)anotherArray;
Availability: OpenStep
Returns a new array which is the concatenation of self and otherArray (in this precise order).
- (
NSString*)
componentsJoinedByString: (
NSString*)separator;
Availability: OpenStep
Returns a string formed by concatenating the objects in the receiver, with the specified separator string inserted between each part.
- (BOOL)
containsObject: (id)anObject;
Availability: OpenStep
Returns
YES
if
anObject belongs to self. No otherwise.
The
[NSObject -isEqual:]
method of
anObject is used to test for equality.
- (unsigned)
count;
Availability: OpenStep
Subclasses
should override this method.
Returns the number of elements contained in the receiver.
- (
NSString*)
description;
Availability: OpenStep
- (
NSString*)
descriptionWithLocale: (
NSDictionary*)locale
indent: (unsigned int)level;
Availability: OpenStep
Returns the receiver as a text property list in the traditional format.
See
[NSString -propertyList]
for details.
If
locale is
nil
, no formatting is done, otherwise entries are formatted according to the
locale, and indented according to
level.
Unless
locale is
nil
, a
level of zero indents items by four spaces, while a
level of one indents them by a tab.
The items in the property list string appear in the same order as they appear in the receiver.
- (id)
firstObjectCommonWithArray: (
NSArray*)otherArray;
Availability: OpenStep
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.
- (void)
getObjects: (id*)aBuffer;
Availability: OpenStep
Copies the objects from the receiver to aBuffer, which must be an area of memory large enough to hold them.
- (void)
getObjects: (id*)aBuffer
range: (
NSRange)aRange;
Availability: OpenStep
Copies the objects from the range aRange of the receiver to aBuffer, which must be an area of memory large enough to hold them.
- (unsigned)
indexOfObject: (id)anObject;
Availability: OpenStep
Returns the index of the first object found in the receiver which is equal to
anObject (using anObject's
[NSObject -isEqual:]
method). Returns NSNotFound on failure.
- (unsigned)
indexOfObject: (id)anObject
inRange: (
NSRange)aRange;
Availability: OpenStep
Returns the index of the first object found in
aRange of receiver which is equal to
anObject (using anObject's
[NSObject -isEqual:]
method). Returns NSNotFound on failure.
- (unsigned)
indexOfObjectIdenticalTo: (id)anObject;
Availability: OpenStep
Returns the index of the specified object in the receiver, or NSNotFound if the object is not present.
- (unsigned)
indexOfObjectIdenticalTo: (id)anObject
inRange: (
NSRange)aRange;
Availability: OpenStep
Returns the index of the specified object in the range of the receiver, or NSNotFound if the object is not present.
- (id)
init;
Availability: OpenStep
In MacOS-X class clusters do not have designated initialisers, and there is a general rule that -init
is treated as the designated initialiser of the class cluster, but that other intitialisers may not work s expected an would need to be individually overridden in any subclass.
GNUstep tries to make it easier to subclass a class cluster, by making class clusters follow the same convention as normal classes, so the designated initialiser is the richest initialiser. This means that all other initialisers call the documented designated initialiser (which calls -init
only for MacOS-X compatibility), and anyone writing a subclass only needs to override that one initialiser in order to have all the other ones work.
For MacOS-X compatibility, you may also need to override various other initialisers. Exactly which ones, you will need to determine by trial on a MacOS-X system... and may vary between releases of MacOS-X. So to be safe, on MacOS-X you probably need to re-implement all the class cluster initialisers you might use in conjunction with your subclass.
- (id)
initWithArray: (
NSArray*)array;
Availability: OpenStep
Initialize the receiver with the contents of
array. The order of
array is preserved.
Invokes
-initWithObjects:count:
- (id)
initWithArray: (
NSArray*)array
copyItems: (BOOL)shouldCopy;
Availability: MacOS-X 10.0.0
Initialize the receiver with the contents of
array. The order of
array is preserved.
If
shouldCopy is
YES
then the objects are copied rather than simply retained.
Invokes
-initWithObjects:count:
- (id)
initWithContentsOfFile: (
NSString*)file;
Availability: OpenStep
Initialises the array with the contents of the specified file, which must contain an array in property-list format.
In GNUstep, the property-list format may be either the OpenStep format (ASCII data), or the MacOS-X format (UTF-8 XML data)... this method will recognise which it is.
If there is a failure to load the file for any reason, the receiver will be released, the method will return nil
, and a warning may be logged.
Works by invoking [NSString -initWithContentsOfFile:]
and [NSString -propertyList]
then checking that the result is an array.
- (id)
initWithContentsOfURL: (
NSURL*)aURL;
Availability: MacOS-X 10.0.0
Initialises the array with the contents of the specified URL, which must contain an array in property-list format.
In GNUstep, the property-list format may be either the OpenStep format (ASCII data), or the MacOS-X format (UTF8 XML data)... this method will recognise which it is.
If there is a failure to load the URL for any reason, the receiver will be released, the method will return nil
, and a warning may be logged.
Works by invoking [NSString -initWithContentsOfURL:]
and [NSString -propertyList]
then checking that the result is an array.
- (id)
initWithObjects: (id)firstObject
,...;
Availability: OpenStep
Initialize the array the list of objects.
May change the value of self before returning it.
- (id)
initWithObjects: (id*)objects
count: (unsigned)count;
Availability: OpenStep
This is a designated initialiser for the class.
Subclasses
should override this method.
This should initialize the array with
count (may be zero)
objects.
Retains each object placed in the array.
Calls
-init
(which does nothing but maintain MacOS-X compatibility), and needs to be re-implemented in subclasses in order to have all other initialisers work.
- (BOOL)
isEqualToArray: (
NSArray*)otherArray;
Availability: OpenStep
Returns YES
if the receiver is equal to otherArray, NO
otherwise.
- (id)
lastObject;
Availability: OpenStep
Returns the last object in the receiver, or nil
if the receiver is empty.
- (void)
makeObjectsPerform: (SEL)aSelector;
Availability: OpenStep removed at OPENSTEP 4.0.0
- (void)
makeObjectsPerform: (SEL)aSelector
withObject: (id)argument;
Availability: OpenStep removed at OPENSTEP 4.0.0
- (void)
makeObjectsPerformSelector: (SEL)aSelector;
Availability: MacOS-X 10.0.0
Makes each object in the array perform aSelector.
This is done sequentially from the first to the last object.
- (void)
makeObjectsPerformSelector: (SEL)aSelector
withObject: (id)arg;
Availability: MacOS-X 10.0.0
Makes each object in the array perform aSelector with arg.
This is done sequentially from the first to the last object.
- (id)
objectAtIndex: (unsigned)index;
Availability: OpenStep
Subclasses
should override this method.
Returns the object at the specified index. Raises an exception of the index is beyond the array.
- (
NSEnumerator*)
objectEnumerator;
Availability: OpenStep
Returns an enumerator describing the array sequentially from the first to the last element.
If you use a mutable subclass of NSArray, you should not modify the array during enumeration.
- (
NSArray*)
pathsMatchingExtensions: (
NSArray*)extensions;
Availability: OpenStep
Assumes that the receiver is an array of paths, and returns an array formed by selecting the subset of those patch matching the specified array of extensions.
- (
NSEnumerator*)
reverseObjectEnumerator;
Availability: OpenStep
Returns an enumerator describing the array sequentially from the last to the first element.
If you use a mutable subclass of NSArray, you should not modify the array during enumeration.
- (
NSData*)
sortedArrayHint;
Availability: OpenStep
Subclasses may provide a hint for sorting... The default GNUstep implementation just returns nil
.
- (
NSArray*)
sortedArrayUsingFunction: (NSComparisonResult(*)(id,id,void*))comparator
context: (void*)context;
Availability: OpenStep
- (
NSArray*)
sortedArrayUsingFunction: (NSComparisonResult(*)(id,id,void*))comparator
context: (void*)context
hint: (
NSData*)hint;
Availability: OpenStep
Returns an autoreleased array in which the objects are ordered according to a sort with comparator, where the comparator function is passed two objects to compare, and the context as the third argument. The hint argument is currently ignored, and may be nil
.
- (
NSArray*)
sortedArrayUsingSelector: (SEL)comparator;
Availability: OpenStep
Returns an autoreleased array in which the objects are ordered according to a sort with comparator.
- (
NSArray*)
subarrayWithRange: (
NSRange)aRange;
Availability: OpenStep
Returns a subarray of the receiver containing the objects found in the specified range aRange.
- (id)
valueForKey: (
NSString*)key;
Availability: MacOS-X 10.0.0
This overrides NSObjects implementation of this method. This method returns an array of objects returned by invoking
-valueForKey:
for each item in the receiver, substituting NSNull for
nil
. A special case: the
key "count" is not forwarded to each object of the receiver but returns the number of objects of the receiver.
- (BOOL)
writeToFile: (
NSString*)path
atomically: (BOOL)useAuxiliaryFile;
Availability: OpenStep
Writes the contents of the array to the file specified by path. The file contents will be in property-list format... under GNUstep this is either OpenStep style (ASCII characters using \U hexadecimal escape sequences for unicode), or MacOS-X style (XML in the UTF8 character set).
If the useAuxiliaryFile flag is YES
, the file write operation is atomic... the data is written to a temporary file, which is then renamed to the actual file name.
If the conversion of data into the correct property-list format fails or the write operation fails, the method returns NO
, otherwise it returns YES
.
NB. The fact that the file is in property-list format does not necessarily mean that it can be used to reconstruct the array using the -initWithContentsOfFile:
method. If the original array contains non-property-list objects, the descriptions of those objects will have been written, and reading in the file as a property-list will result in a new array containing the string descriptions.
- (BOOL)
writeToURL: (
NSURL*)url
atomically: (BOOL)useAuxiliaryFile;
Availability: MacOS-X 10.0.0
Writes the contents of the array to the specified url. This functions just like -writeToFile:atomically:
except that the output may be written to any URL, not just a local file.
- Declared in:
- Foundation/NSArray.h
Availability: OpenStep
NSMutableArray
is the mutable version of
NSArray
. It provides methods for altering the contents of the array.
Method summary
+ (id)
arrayWithCapacity: (unsigned)numItems;
Availability: OpenStep
Creates an autoreleased mutable array able to store at least
numItems. See the
-initWithCapacity:
method.
- (void)
addObject: (id)anObject;
Availability: OpenStep
Subclasses
should override this method.
Adds anObject at the end of the array, thus increasing the size of the array. The object is retained upon addition.
- (void)
addObjectsFromArray: (
NSArray*)otherArray;
Availability: OpenStep
Adds each object from otherArray to the receiver, in first to last order.
- (void)
exchangeObjectAtIndex: (unsigned int)i1
withObjectAtIndex: (unsigned int)i2;
Availability: MacOS-X 10.0.0
Swaps the positions of two objects in the array. Raises an exception if either array index is out of bounds.
- (id)
initWithCapacity: (unsigned)numItems;
Availability: OpenStep
This is a designated initialiser for the class.
Subclasses
should override this method.
Initialise the array with the specified capacity ... this should ensure that the array can have
numItems added efficiently.
Calls
-init
(which does nothing but maintain MacOS-X compatibility), and needs to be re-implemented in subclasses in order to have all other initialisers work.
- (void)
insertObject: (id)anObject
atIndex: (unsigned)index;
Availability: OpenStep
Subclasses
should override this method.
Inserts an object into the receiver at the specified location.
Raises an exception if given an array index which is too large.
The size of the array increases by one.
The object is retained by the array.
- (void)
removeAllObjects;
Availability: OpenStep
Removes all objects from the receiver, leaving an empty array.
- (void)
removeLastObject;
Availability: OpenStep
Removes the last object in the array. Raises an exception if the array is already empty.
- (void)
removeObject: (id)anObject;
Availability: OpenStep
Removes all occurrences of
anObject (found by anObject's
[NSObject -isEqual:]
method) from the receiver.
- (void)
removeObject: (id)anObject
inRange: (
NSRange)aRange;
Availability: OpenStep
Removes all occurrences of
anObject (found by the
[NSObject -isEqual:]
method of
anObject)
aRange in the receiver.
- (void)
removeObjectAtIndex: (unsigned)index;
Availability: OpenStep
Subclasses
should override this method.
Removes an object from the receiver at the specified location.
The size of the array decreases by one.
Raises an exception if given an array index which is too large.
- (void)
removeObjectIdenticalTo: (id)anObject;
Availability: OpenStep
Removes all occurrences of anObject (found by pointer equality) from the receiver.
- (void)
removeObjectIdenticalTo: (id)anObject
inRange: (
NSRange)aRange;
Availability: OpenStep
Removes all occurrences of anObject (found by pointer equality) from aRange in the receiver.
- (void)
removeObjectsFromIndices: (unsigned*)indices
numIndices: (unsigned)count;
Availability: OpenStep
Supplied with a C array of indices containing count values, this method removes all corresponding objects from the receiver. The objects are removed in such a way that the removal is safe irrespective of the order in which they are specified in the indices array.
- (void)
removeObjectsInArray: (
NSArray*)otherArray;
Availability: OpenStep
Removes from the receiver, all the objects present in
otherArray, as determined by using the
[NSObject -isEqual:]
method.
- (void)
removeObjectsInRange: (
NSRange)aRange;
Availability: OpenStep
Removes all the objects in aRange from the receiver.
- (void)
replaceObjectAtIndex: (unsigned)index
withObject: (id)anObject;
Availability: OpenStep
Subclasses
should override this method.
Places an object into the receiver at the specified location.
Raises an exception if given an array index which is too large.
The object is retained by the array.
- (void)
replaceObjectsInRange: (
NSRange)aRange
withObjectsFromArray: (
NSArray*)anArray;
Availability: OpenStep
Replaces objects in the receiver with those from anArray.
Raises an exception if given a range extending beyond the array.
- (void)
replaceObjectsInRange: (
NSRange)aRange
withObjectsFromArray: (
NSArray*)anArray
range: (
NSRange)anotherRange;
Availability: OpenStep
Replaces objects in the receiver with some of those from anArray.
Raises an exception if given a range extending beyond the array.
- (void)
setArray: (
NSArray*)otherArray;
Availability: OpenStep
Sets the contents of the receiver to be identical to the contents of otherArray.
- (void)
setValue: (id)value
forKey: (
NSString*)key;
Availability: MacOS-X 10.0.0
Call setValue:forKey: on each of the receiver's items with the value and key.
- (void)
sortUsingFunction: (NSComparisonResult(*)(id,id,void*))compare
context: (void*)context;
Availability: OpenStep
Sorts the array according to the supplied compare function with the context information.
- (void)
sortUsingSelector: (SEL)comparator;
Availability: OpenStep
Sorts the array according to the supplied comparator.
- Declared in:
- Foundation/NSArray.h
Availability: OpenStep
Description forthcoming.
Method summary
- (unsigned)
insertionPosition: (id)item
usingFunction: (NSComparisonResult(*)(id,id,void*))sorter
context: (void*)context;
Availability: OpenStep
Description forthcoming.
- (unsigned)
insertionPosition: (id)item
usingSelector: (SEL)comp;
Availability: OpenStep
Description forthcoming.
Up