开发者

initWithObjects - Expected Identifier

开发者 https://www.devze.com 2023-03-25 12:38 出处:网络
I am just开发者_StackOverflow中文版 learning objective-C, and have a book with code like this: NSArray *foods = [[[NSArray alloc] initWithObjects: @\"cheese\", @\"ham\", nil]];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消