- Declared In:
- NSArray+Extensions.h
Retrieving individual objectsHandling subarrays
- - singleObject
- - firstObject
- + applyFirstObjectPatch
Rearranging the array
- - subarrayToIndex:
- - subarrayFromIndex:
- - isSubarrayOfArray:atOffset:
- - indexOfSubarray:
Mapping the array
- - reversedArray
- - shuffledArray
- - sortedArray
- - sortedArrayByComparingAttribute:
- - flattenedArray
List files
- - arrayByMappingWithDictionary:
- - arrayByMappingWithSelector:
- - arrayByMappingWithSelector:withObject:
- + librarySearchPaths
- + arrayWithFilesOfType:inPath:
- + arrayWithFilesOfType:inLibrary:
+ (void)applyFirstObjectPatch
See description of firstObject.
+ (NSArray *)arrayWithFilesOfType:(NSString *)type inLibrary:(NSString *)libraryName
Creates and returns an array of NSString objects. These refer to all files of a type specified in type that can be found in a directory named libraryName in any of the standard library locations as returned by NSSearchPathForDirectoriesInDomains.
+ (NSArray *)arrayWithFilesOfType:(NSString *)type inPath:(NSString *)aPath
Creates and returns an array of NSString objects. These refer to all files of the type specified in type that can be found in the directory aPath.
+ (NSArray *)librarySearchPaths
Returns an array containing all library paths.
- (NSArray *)arrayByMappingWithDictionary:(NSDictionary *)mapping
Uses each object in the receiver as a key and looks up the corresponding value in mapping. All these values are added in the same order to the array returned. Note that this method raises an Exception if any of the objects in the receiver are not found as a key in mapping.
- (NSArray *)arrayByMappingWithSelector:(SEL)selector
Invokes the method described by selector in each object in the receiver. All returned values are added in the same order to the array returned.
- (NSArray *)arrayByMappingWithSelector:(SEL)selector withObject:(id)object
Invokes the method described by selector in each object in the receiver, passing object as an argument. All returned values are added in the same order to the array returned.
- (id)firstObject
Return the object at index 0 or nil
if the array is empty. Note: The method firstObject is also implemented in the HTML framework which is sometimes loaded in AppKit applications. Unfortunately, its implemenation differs in that it raises an exception if the array is empty. (Don't ask why they did that!) So, you either live with this or call applyFirstObjectPatch before the HTML framework is loaded.
- (NSArray *)flattenedArray
If the receiver contains instances of NSArray the objects from the embedded array are transferred to the receiver and the embedded array is deleted. This method works recursively which means that embedded arrays are also flattened before their contents are transferred.
- (unsigned int)indexOfSubarray:(NSArray *)other
Returns the first index at which otherArray is contained in the receiver; or NSNotFound
otherwise.
- (BOOL)isSubarrayOfArray:(NSArray *)other atOffset:(int)offset
Returns YES if the receiver is contained in otherArray at offset.
- (NSArray *)reversedArray
Returns a new array that is a copy of the receiver with the objects arranged in reverse.
- (NSArray *)shuffledArray
Returns a new array that is a copy of the receiver with the objects rearranged randomly.
- (id)singleObject
If the array contains exactly one object this is returned. Otherwise an NSInternalInconsistencyException is raised.
- (NSArray *)sortedArray
Returns a new array that is a copy of the receiver with the objects sorted objects according to their compare: method
- (NSArray *)sortedArrayByComparingAttribute:(NSString *)attributeName
Returns a new array that is a copy of the receiver with the objects sorted according to the values of their attribute attributeName. These are retrieved using key/value coding.
- (NSArray *)subarrayFromIndex:(unsigned int)index
Returns an array containing all objects from the receiver starting with the object at index.
- (NSArray *)subarrayToIndex:(unsigned int)index
Returns an array containing all objects from the receiver up to (not including) the object at index.