Joe
Joe

Reputation: 1344

expected identifier error in xcode

i get this error "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?

Upvotes: 1

Views: 5065

Answers (2)

Helen
Helen

Reputation: 3981

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]];

Upvotes: 2

Vladimir
Vladimir

Reputation: 170819

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.

Upvotes: 4

Related Questions