Type Method

arrayWithObjects:count:

Creates and returns an array that includes a given number of objects from a given C array.

Declaration

+ (instancetype)arrayWithObjects:(ObjectType  _Nonnull const *)objects count:(NSUInteger)cnt;

Parameters

objects

A C array of objects.

count

The number of values from the objects C array to include in the new array. This number will be the count of the new array—it must not be negative or greater than the number of elements in objects.

Return Value

A new array including the first count objects from objects.

Discussion

Elements are added to the new array in the same order they appear in objects, up to but not including index count. For example:

NSString *strings[3];
strings[0] = @"First";
strings[1] = @"Second";
strings[2] = @"Third";
 
NSArray *stringsArray = [NSArray arrayWithObjects:strings count:2];
// strings array contains { @"First", @"Second" }

See Also

Creating an Array

+ array

Creates and returns an empty array.

+ arrayWithArray:

Creates and returns an array containing the objects in another given array.

+ arrayWithContentsOfFile:

Creates and returns an array containing the contents of the file specified by a given path.

Deprecated
+ arrayWithContentsOfURL:

Creates and returns an array containing the contents specified by a given URL.

Deprecated
+ arrayWithObject:

Creates and returns an array containing a given object.

+ arrayWithObjects:

Creates and returns an array containing the objects in the argument list.