arrayWithObjects:
Creates and returns an array containing the objects in the argument list.
Declaration
+ (instancetype) arrayWithObjects:(ObjectType) firstObj;Parameters
- firstObj:
The first object for the array.
Return Value
An array containing the objects in the argument list.
Discussion
Pass comma-separated list of trailing variadic arguments as additional objects, ending with nil.
The following code example creates an array containing three different types of element:
NSDate *aDate = [NSDate distantFuture];
NSValue *aValue = @(5);
NSString *aString = @"hello";
NSArray *array = [NSArray arrayWithObjects:aDate, aValue, aString, nil];Alternatively, you can use array literal syntax in Objective-C or Swift to create an array containing given objects:
NSArray *array = @[@"alpha", @"bravo", @"charlie"];