Rich Bradshaw
Rich Bradshaw

Reputation: 73045

initWithObjects - Expected Identifier

I am just learning objective-C, and have a book with code like this:

NSArray *foods = [[[NSArray alloc] initWithObjects: @"cheese", @"ham", nil]];

This has an error – "Expected Identifier". What does this mean, and what should this code look like?

(I'm using the newest xCode and iOS version, with the idea that by the time iOS5 is out, I'll know it!)

Upvotes: 1

Views: 4784

Answers (2)

Colin Moseley
Colin Moseley

Reputation: 11

The extra brackets are not necessary but are also not a problem as long as they are balanced. The problem here is that initWithObjects requires objects, and you are providing strings rather than NSString objects.

Upvotes: 1

MByD
MByD

Reputation: 137432

I think that's because you have extra brackets, it should be:

NSArray *foods = [[NSArray alloc] initWithObjects: @"cheese", @"ham", nil] ;

Upvotes: 9

Related Questions