Declared in GHNSArray+Utils.h
GHNSArray+Utils.m

Overview

Utilities for arrays.

Tasks

Class Methods

gh_arrayWithObject:

Safe array with object.

+ (NSArray *)gh_arrayWithObject:(id)obj

Parameters

obj

Object

Return Value

Array with object. Returns empty if obj is nil.

Declared In

GHNSArray+Utils.h

Instance Methods

gh_arrayByReversingArray

Return new reversed array. Use reverseObjectEnumerator if you want to enumerate values in reverse.

- (NSArray *)gh_arrayByReversingArray

Return Value

Reversed array

Declared In

GHNSArray+Utils.h

gh_compact

Remove all instances of NSNull.

- (NSArray *)gh_compact

Return Value

New array with NSNull instances removed. Returns self if no NSNull’s were found.

Declared In

GHNSArray+Utils.h

gh_filter:

Filter array.

- (NSArray *)gh_filter:(BOOL ( ^ ) ( id obj , NSInteger index ))filterBlock

Parameters

filterBlock

Filter block

Declared In

GHNSArray+Utils.h

gh_firstObject

First object or nil if array is empty.

- (id)gh_firstObject

Return Value

Object at index 0

Declared In

GHNSArray+Utils.h

gh_objectAtIndex:

Safe object at index.

- (id)gh_objectAtIndex:(NSInteger)index

Parameters

index

Index

Return Value

Object at index, or nil if index < 0 or >= count

Declared In

GHNSArray+Utils.h

gh_objectAtIndex:withDefault:

Safe object at index with default.

- (id)gh_objectAtIndex:(NSInteger)index withDefault:(id)withDefault

Parameters

index

Index

withDefault

Default if not found

Return Value

Object at index, or default value if index < 0 or >= count

Declared In

GHNSArray+Utils.h

gh_randomObject:

Random object in the array.

- (id)gh_randomObject:(unsigned int)seed

Parameters

seed

Seed, if 0, will use the current time to seed

Return Value

Random object

Declared In

GHNSArray+Utils.h

gh_subarrayFromLocation:

Get sub-array from location to end.

- (NSArray *)gh_subarrayFromLocation:(NSInteger)location

Parameters

location

Index

Return Value

Sub-array

Declared In

GHNSArray+Utils.h

gh_subarrayWithRange:

Safe subarrayWithRange that checks range. If the length is out of bounds will return all elements from location to the end. If the location is out of bounds will return nil.

- (NSArray *)gh_subarrayWithRange:(NSRange)range

Parameters

range

Range

Return Value

Sub-array

Declared In

GHNSArray+Utils.h