错误:预期';' 在 Xcode 中的“界面”之前

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1113101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:40:30  来源:igfitidea点击:

Error: expected ';' before 'interface' in Xcode

iphoneobjective-cxcode

提问by RCIX

I'm trying to run through the Hello World tutorial for the iPhone and i get this error: Error: expected ';' before 'interface' I have checked and my files are identical (except for whitespace) to the tutorials, and i can't figure out why i'm having this problem. I can provide code if necessary.

我正在尝试浏览 iPhone 的 Hello World 教程,但出现此错误:错误:预期 ';' 在“界面”之前,我已经检查过并且我的文件与教程相同(空格除外),我不知道为什么我会遇到这个问题。如果需要,我可以提供代码。

HelloWorldAppDelegate.h:

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

HelloWorldAppDelegate.m:

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

MyViewController.h:

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

MyViewController.m:

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

回答by wadesworld

Here's your problem, on your first line:

这是你的问题,在你的第一行:

@class MyViewController

@class MyViewController

Where's the semicolon?

分号在哪里?

回答by Rose Perrone

You don't have this problem, but when I got this error, I had a spare letter at the very beginning of the implementation file of the class that produced the error:

你没有这个问题,但是当我得到这个错误时,我在产生错误的类的实现文件的最开头有一个备用字母:

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

#import "ManagedObjectAttributeEditor.h"

@implementation ManagedObjectAttributeEditor

回答by kperryua

You probably have forgotten a semi-colon after a struct or enum decl or something in the same file or an included file.

您可能忘记了 struct 或 enum decl 或同一文件或包含文件中的某些内容之后的分号。