EngineKit
NSArray(ObjectiveSugar) Category Reference

Instance Methods

("Please use -firstObject instead") - DEPRECATED_MSG_ATTRIBUTE
 
("Please use -lastObject instead") - DEPRECATED_MSG_ATTRIBUTE
 
(id) - sample
 
(id) - anyObject
 Alias for -sample.
 
(id) - objectForKeyedSubscript:
 
(void) - each:
 
(void) - eachWithIndex:
 
(void) - each:options:
 
(void) - eachWithIndex:options:
 
(BOOL) - includes:
 
(NSArray *) - take:
 
(NSArray *) - takeWhile:
 
(NSArray *) - map:
 
(NSArray *) - select:
 
(id) - detect:
 
(id) - find:
 
(NSArray *) - reject:
 
(NSArray *) - flatten
 
(NSArray *) - compact
 
(NSString *) - join
 
(NSString *) - join:
 
(NSArray *) - sort
 
(NSArray *) - sortBy:
 
(NSArray *) - reverse
 
(NSArray *) - intersectionWithArray:
 
(NSArray *) - unionWithArray:
 
(NSArray *) - relativeComplement:
 
(NSArray *) - symmetricDifference:
 
(id) - reduce:
 
(id) - reduce:withBlock:
 
(NSArray *) - unique
 

Method Documentation

- (NSArray *) compact

Remove all the nulls from array

Returns
A copy of the given array without NSNulls
- ("Please use -firstObject instead") DEPRECATED_MSG_ATTRIBUTE

The first item in the array, or nil.

Returns
The first item in the array, or nil.
- ("Please use -lastObject instead") DEPRECATED_MSG_ATTRIBUTE

The last item in the array, or nil.

Returns
The last item in the array, or nil.
- (id) detect: (BOOL(^)(id object))  block

Iterate through current array returning the first element meeting a criteria.

Parameters
blockA block that returns YES/NO
Returns
The first matching element
- (void) each: (void(^)(id object))  block

A simpler alias for enumerateObjectsUsingBlock

Parameters
blockA block with the object in its arguments.
- (void) each: (void(^)(id object))  block
options: (NSEnumerationOptions)  options 

A simpler alias for enumerateObjectsWithOptions:usingBlock:

Parameters
blockA block with the object in its arguments.
optionsEnumerating options.
- (void) eachWithIndex: (void(^)(id object, NSUInteger index))  block

A simpler alias for enumerateObjectsUsingBlock which also passes in an index

Parameters
blockA block with the object in its arguments.
- (void) eachWithIndex: (void(^)(id object, NSUInteger index))  block
options: (NSEnumerationOptions)  options 

A simpler alias for enumerateObjectsWithOptions:usingBlock: which also passes in an index

Parameters
blockA block with the object in its arguments.
optionsEnumerating options.
- (id) find: (BOOL(^)(id object))  block

Alias for detect. Iterate through current array returning the first element meeting a criteria.

Parameters
blockA block that returns YES/NO
Returns
The first matching element
- (NSArray *) flatten

Recurse through self checking for NSArrays and extract all elements into one single array

Returns
An array of all held arrays merged
- (BOOL) includes: (id)  object

An alias for containsObject

Parameters
objectAn object that the array may or may not contain.
- (NSArray *) intersectionWithArray: (NSArray *)  array

Return all the objects that are in both self and array. Alias for Ruby's & operator

Returns
An array of objects common to both arrays
- (NSString *) join

Alias for componentsJoinedByString with a default of no seperator

Returns
A string of all objects joined with an empty string
- (NSString *) join: (NSString *)  separator

Alias for componentsJoinedByString

Returns
A string of all objects joined with the seperator string
- (NSArray *) map: (id(^)(id object))  block

Iterate through the current array running the block on each object and returning an array of the changed objects.

Parameters
blockA block that passes in each object and returns a modified object
Returns
An array of modified elements
- (id) objectForKeyedSubscript: (id< NSCopying >)  key

Allow subscripting to fetch elements within the specified range

Parameters
keyAn NSString or NSValue wrapping an NSRange. It's intended to behave like Ruby's array range accessors.
   Given array of 10 elements, e.g. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], you can perform these operations:
   array[@"1..3"] will give you [2, 3, 4]
   array[@"1...3"] will give you [2, 3] (last value excluded)
   array[@"1,3"] implies NSRange(location: 1, length: 3), and gives you [2, 3, 4]
Returns
An array with elements within the specified range
- (id) reduce: (id(^)(id accumulator, id object))  block

Return a single value from an array by iterating through the elements and transforming a running total.

Returns
A single value that is the end result of apply the block function to each element successively.
- (id) reduce: (id)  initial
withBlock: (id(^)(id accumulator, id object))  block 

Same as -reduce, with initial value provided by yourself

- (NSArray *) reject: (BOOL(^)(id object))  block

Iterate through current array asking whether to remove each element.

Parameters
blockA block that returns YES/NO for whether the object should be removed
Returns
An array of elements not rejected
- (NSArray *) relativeComplement: (NSArray *)  array

Return all the objects in self that are not in array. Alias for Ruby's - operator

Returns
An array of the self without objects in array
- (NSArray *) reverse

Alias for reverseObjectEnumerator.allObjects

Returns a reversed array

- (id) sample

A random element in the array, or nil.

Returns
A random element in the array, or nil.
- (NSArray *) select: (BOOL(^)(id object))  block

Iterate through current array asking whether to keep each element.

Parameters
blockA block that returns YES/NO for whether the object should stay
Returns
An array of elements selected
- (NSArray *) sort

Run the default comparator on each object in the array

Returns
A sorted copy of the array
- (NSArray *) sortBy: (NSString *)  key

Sorts the array using the the default comparator on the given key

Returns
A sorted copy of the array
- (NSArray *) symmetricDifference: (NSArray *)  array

Return all the objects that are unique to each array individually Alias for Ruby's ^ operator. Equivalent of a - b | b - a

Returns
An array of elements which are in either of the arrays and not in their intersection.
- (NSArray *) take: (NSUInteger)  numberOfElements

Take the first numberOfElements out of the array, or the maximum amount of elements if it is less.

Parameters
numberOfElementsNumber of elements to take from array
Returns
An array of elements
- (NSArray *) takeWhile: (BOOL(^)(id object))  block

Passes elements to the block until the block returns NO, then stops iterating and returns an array of all prior elements.

Parameters
blockA block that returns YES/NO
Returns
An array of elements
- (NSArray *) unionWithArray: (NSArray *)  array

Return all the objects that in both self and array combined. Alias for Ruby's | operator

Returns
An array of the two arrays combined
- (NSArray *) unique

Produces a duplicate-free version of the array

Returns
a new array with all unique elements

The documentation for this category was generated from the following files: