错误:预期';' 在Xcode中的'interface'之前

RCI*_*CIX 1 iphone xcode objective-c

我正在尝试运行iPhone的Hello World教程,我收到此错误:错误:预期';' 在'界面'之前我已经检查过,我的文件是相同的(除了空白)到教程,我无法弄清楚为什么我有这个问题.如有必要,我可以提供代码.

HelloWorldAppDelegate.h:

//
//  HelloWorldAppDelegate.h
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MyViewController

@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MyViewController *myViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) MyViewController *myViewController;

@end
Run Code Online (Sandbox Code Playgroud)

HelloWorldAppDelegate.m:

//
//  HelloWorldAppDelegate.m
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "MyViewController.h"
#import "HelloWorldAppDelegate.h"

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize myViewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    MyViewController *aViewController = [[MyViewController alloc]
                                         initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
    [self setMyViewController:aViewController];
    [aViewController release];
    UIView *controllersView = [myViewController view];
    [window addSubview:controllersView];

    [window makeKeyAndVisible];
}


- (void)dealloc {
    [myViewController release]; 
    [window release];
    [super dealloc];
}


@end
Run Code Online (Sandbox Code Playgroud)

MyViewController.h:

//
//  MyViewController.h
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {

}

@end
Run Code Online (Sandbox Code Playgroud)

MyViewController.m:

//
//  MyViewController.m
//  HelloWorld
//
//  Created by RCIX on 7/10/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "MyViewController.h"


@implementation MyViewController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
Run Code Online (Sandbox Code Playgroud)

wad*_*rld 6

这是你的第一行问题:

@class MyViewController

用分号在哪里?


Ros*_*one 6

你没有这个问题,但是当我收到这个错误时,我在产生错误的类的实现文件的最开头有一个空格:

G//
//  ManagedObjectAttributeEditor.m
//  App
//
//  Created by Rose Perrone on 7/28/10.
//  Copyright 2010 Company. All rights reserved.
//

#import "ManagedObjectAttributeEditor.h"

@implementation ManagedObjectAttributeEditor
Run Code Online (Sandbox Code Playgroud)