I am just开发者_StackOverflow中文版 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!)
I think that's because you have extra brackets, it should be:
NSArray *foods = [[NSArray alloc] initWithObjects: @"cheese", @"ham", nil] ;
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.
精彩评论