crazy_tiger_corp crazy_tiger_corp - 7 months ago 64
iOS Question

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

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.


Duplicate interface definition for class 'ViewController'

This is the code:

#import "ViewController.h"

@interface ViewController // First error here.


@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 release]; // fourth error

Sorry about the weird formatting but I couldn't get this to format into code.

Thank you in advance


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.