0

I am getting this error message and matched my brackets and couldn't find anything wrong. Can you find what's wrong? I really need help. Please. The error I am getting is this "Missing '[' at start of message send expression" I have commented where it occurs down near the end of my code. Please help me.

Thank you.

@interface HomeViewOne ()

@end

@implementation HomeViewOne

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)switchScreenHome:(id)sender {

    //Code to switch screen from main menu to game
    ViewController *view [[ViewController alloc] initWithNibName:nil bundle:nil];  //My error is on this line, it says Missing '[' at start of message send expression
    [self presentModalViewController:view animated:YES];
}
@end
Alfonso
  • 8,386
  • 1
  • 43
  • 63
  • I moved the stack trace to the relevant follow-up question [here](http://stackoverflow.com/questions/22737897/thread-1-signal-sigabrt-can-someone-help-me) – Alfonso Mar 29 '14 at 23:03

3 Answers3

1

That line should be:

ViewController *view = [[ViewController alloc] initWithNibName:nil bundle:nil];  //My error is on this line, it says Missing '[' at start of message send expression

you need to add a "=".

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

The code is missing something useful, like an =.

Thus the [..] is not parsed in a meaningful fashion (i.e. as an expression used in an assignment) and results in the given syntax error.


The code is actually parsed as an variable array declaration, consider

X* x[..];

where .. is

[ViewController alloc] initWithNibName:nil bundle:nil

which results in "Missing '[' at start of message send expression", just as if that code appeared in a statement by itself. Adding another pair of []'s would "fix" that, and actually declare a variable-length array. However, you definetly don't want a VLA here.. just add the assignment operator already.

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220
1

The line with the error should actually be:

ViewController *view = [[ViewController alloc] initWithNibName:nil bundle:nil];  

Note the '=' character

jancakes
  • 456
  • 4
  • 10