surfaspen
surfaspen

Reputation: 391

Getting compiler errors Expected Identifier / Expected Method Body

I'm currently working on an app where I have 2 main veiws in the storyboard; ViewController and MainViewController.

I'm coming up with the Expected Identifier and Expected method body errors in my MainViewController.m.

Here is the file:

//
//  MainView.m
//  Ski Finder Intro
//
//  Created by Hunter Bryant on 10/20/12.
//  Copyright (c) 2012 Hunter Bryant. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController


- (id)initWithNibName:@"MainViewController" bundle:Nil  //Here are both of the errors.
{
    self = [super initWithNibName:@"MainViewController'" bundle:Nil];
    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.
}

@end

Upvotes: 0

Views: 887

Answers (1)

CodaFi
CodaFi

Reputation: 43330

You seem to be confusing method declarations (an override in this case), and actually sending a message in Objective-C. Your method body should look like this:

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil //No more errors.

To use the method in a message, call [[MyClass alloc]initWithNibName:@"MainViewController" bundle:nil];

And as a sidenote: -init... flavored messages are almost never called by the class itself, because it makes little sense, and would create some interesting retain cycles if implemented "properly".

Upvotes: 2

Related Questions