Xcode 6'类'ViewController'的重复接口定义错误 [英] error with Xcode 6 'Duplicate interface definition for class 'ViewController'
问题描述
我正在使用 Xcode 6 按照 2012 年的基本教程编写应用程序.该教程是使用 Xcode 4.3 制作的,我确信我完全按照我通过观察问题区域进行的仔细检查来遵循它.我对这种类型的编程很陌生,因为我通常处理游戏开发和机器人,但之前做过一些.
I'm programming an app following a basic tutorial from 2012 using Xcode 6. The tutorial was made using Xcode 4.3 and I'm sure I have followed it exactly as I have double checked by watching through the problem areas. I'm quite new to this type of programming as I usually deal with game development and robots but have done a little before.
错误:
类ViewController"的重复接口定义
Duplicate interface definition for 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
对于奇怪的格式很抱歉,但我无法将其格式化为代码.
Sorry about the weird formatting but I couldn't get this to format into code.
提前致谢
推荐答案
您需要将 ()
添加到您的 @interface ViewController
行.
You need to add ()
to your @interface ViewController
line.
@interface ViewController()
这在 iOS 中称为私有类别,用于在您的实现文件中定义私有方法和属性.
This is called a private category in iOS, and it's used to define private methods and properties in your implementation file.
在您的 .h 文件中,您会发现接口声明为 @interface ViewController
,这就是编译器认为您声明它两次的原因.使用私有类别(@interface ViewController()
)告诉编译器您实际上是在扩展已经定义的接口(称为 ViewController)的功能,添加私有方法和属性.
In your .h file, you'll find the interface declared as @interface ViewController
, and that's why the compiler thinks you're declaring it twice. Using a private category (@interface ViewController()
) tells the compiler that you're actually extending the functionality of your already defined interface (called ViewController), adding private methods and properties.
这篇关于Xcode 6'类'ViewController'的重复接口定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!