Xcode 6 错误 class 'ViewController' 的重复接口定义

error with Xcode 6 'Duplicate interface definition for class 'ViewController'

我正在按照 2012 年的基本教程使用 Xcode 6 编写应用程序。该教程是使用 Xcode 4.3 制作的,我确信我已经完全按照我的双通过观察问题区域进行检查。我对这种类型的编程很陌生,因为我通常处理游戏开发和机器人,但之前做过一点。

错误:

class'ViewController'

的重复接口定义

这是代码:

 #import "ViewController.h"

 @interface ViewController // First error here.

 @end

 @implementation ViewController

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

   -(void) presentMessage:(NSString *)message {
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Title"         message: message delegate: nil cancelButtonTitle:@"Ok" otherButtonTitles: nil ];

[alert show];
[alert release]; // second error.
}

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {
UILocalNotification *notification = [[UILocalNotification alloc] init];

...    

[notification release]; // third error
}

-(IBAction) buttonTapped:(id)sender {

    dateFormatter...

[dateFormatter release]; // fourth error
 }
   @end

对于奇怪的格式感到抱歉,但我无法将其格式化为代码。

提前致谢

您需要将 () 添加到 @interface ViewController 行。

@interface ViewController()

这在iOS中称为私有类别,用于在您的实现文件中定义私有方法和属性。

在您的 .h 文件中,您会发现接口声明为 @interface ViewController,这就是编译器认为您声明它两次的原因。使用私有类别 (@interface ViewController()) 告诉编译器您实际上是在扩展已定义接口(称为 ViewController)的功能,添加私有方法和属性。

此处的简单解决方案..对我有用

转到编辑方案 -> Select 构建 -> 构建选项取消选中并行化构建

现在运行你的应用程序