开发者

expected identifier error in xcode

开发者 https://www.devze.com 2023-01-13 06:00 出处:网络
i get this error开发者_如何学C \"expected identifier before \'OBJC_STRING\' token\" on this line of code:

i get this error开发者_如何学C "expected identifier before 'OBJC_STRING' token" on this line of code:

- (id)initWithNibName:(NSString *)@"Landscape.xib" bundle:(NSBundle *)mainBundle {

and im not sure why, can anyone help?


In method declaration you can't use string literals for parameter name. Declare it

- (id)initWithNibName:(NSString *)name bundle:(NSBundle *)mainBundle {
...

and pass @"Landscape.xib" as parameter when call that method

P.S. not sure if that's relevant to your question or not, but just in case - objective-c does not support default values for function parameters.


You cannot pass a string in like that. You would use:

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)mainBundle {

...

}

and call it from some other line of code like this:

[[Class alloc] initWithNibName:@"Landscape.xib" bundle:[NSBundle mainBundle]];
0

精彩评论

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