问题
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.
error:
Duplicate interface definition for class 'ViewController'
This is the code:
#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.
Thank you in advance
回答1:
You need to add ()
to your @interface ViewController
line.
@interface ViewController()
This is called a private category in iOS, and it's used to define private methods and properties in your implementation file.
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.
回答2:
Simple solution here..it worked for me
Go to edit scheme -> Select Build -> Build option untick the Parallelize Build
Now run your App
来源:https://stackoverflow.com/questions/32491093/error-with-xcode-6-duplicate-interface-definition-for-class-viewcontroller