NSArray (EDExtensions)


Declared In:
NSArray+Extensions.h


Category Description

Various common extensions to NSArray.


Method Types

Retrieving individual objects
- singleObject
- firstObject
+ applyFirstObjectPatch
Handling subarrays
- subarrayToIndex:
- subarrayFromIndex:
- isSubarrayOfArray:atOffset:
- indexOfSubarray:
Rearranging the array
- reversedArray
- shuffledArray
- sortedArray
- sortedArrayByComparingAttribute:
- flattenedArray
Mapping the array
- arrayByMappingWithDictionary:
- arrayByMappingWithSelector:
- arrayByMappingWithSelector:withObject:
List files
+ librarySearchPaths
+ arrayWithFilesOfType:inPath:
+ arrayWithFilesOfType:inLibrary:


Class Methods

applyFirstObjectPatch

+ (void)applyFirstObjectPatch

See description of firstObject.


arrayWithFilesOfType:inLibrary:

+ (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.


arrayWithFilesOfType:inPath:

+ (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.


librarySearchPaths

+ (NSArray *)librarySearchPaths

Returns an array containing all library paths.


Instance Methods

arrayByMappingWithDictionary:

- (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.


arrayByMappingWithSelector:

- (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.


arrayByMappingWithSelector:withObject:

- (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.


firstObject

- (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.


flattenedArray

- (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.


indexOfSubarray:

- (unsigned int)indexOfSubarray:(NSArray *)other

Returns the first index at which otherArray is contained in the receiver; or NSNotFound otherwise.


isSubarrayOfArray:atOffset:

- (BOOL)isSubarrayOfArray:(NSArray *)other atOffset:(int)offset

Returns YES if the receiver is contained in otherArray at offset.


reversedArray

- (NSArray *)reversedArray

Returns a new array that is a copy of the receiver with the objects arranged in reverse.


shuffledArray

- (NSArray *)shuffledArray

Returns a new array that is a copy of the receiver with the objects rearranged randomly.


singleObject

- (id)singleObject

If the array contains exactly one object this is returned. Otherwise an NSInternalInconsistencyException is raised.


sortedArray

- (NSArray *)sortedArray

Returns a new array that is a copy of the receiver with the objects sorted objects according to their compare: method


sortedArrayByComparingAttribute:

- (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.


subarrayFromIndex:

- (NSArray *)subarrayFromIndex:(unsigned int)index

Returns an array containing all objects from the receiver starting with the object at index.


subarrayToIndex:

- (NSArray *)subarrayToIndex:(unsigned int)index

Returns an array containing all objects from the receiver up to (not including) the object at index.


Version 2.2 Copyright ©2003. All Rights Reserved.