Type Method

arrayWithObject:

Creates and returns an array containing a given object.

Declaration

+ (instancetype)arrayWithObject:(ObjectType)anObject;

Parameters

anObject

An object.

Return Value

An array containing the single element anObject.

Discussion

Alternatively, you can use array literal syntax in Objective-C or Swift to create an array containing a given object:

NSArray *array = @[@"Hello, world!"];

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
+ arrayWithObjects:

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

+ arrayWithObjects:count:

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