0

Possible Duplicate:
NSArray creation with variable argument lists in Objective-C

that's it actually the question is very simple. Xcode suggests that the last item is "nil" and I was wondering why.

array1 = [[NSArray alloc] initWithObjects: @"one", @"two", @"three", @"four", nil];
1

2 Answers 2

1

A null-termination (nil) character is used to determine the length of an array. Failure to properly terminate an array can result in buffer overflows and other undefined behavior.

Sign up to request clarification or add additional context in comments.

Comments

0

Aside from redirecting to the docs about NSArray initWithObjects, it is worth noting that in general, with variadic functions (i.e. functions that take a variable number of arguments), either you specify the number of arguments upfront, or you terminate the argument list in some way. Nil is a good way of terminating the argument list and is the approach taken with initWithObjects.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.