Xcode 6的错误”ViewController’类的重复接口定义

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

错误:

类’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)的function,添加私有方法和属性。

这里简单的解决方案……对我有用

转到编辑方案 – >选择构建 – >构建选项取消勾选并行化构建

现在运行你的应用程序