Ali Ali - 1 year ago 100
Objective-C Question

duplicate interface declaration for class 'test_coredataAppDelegate'

two errors suddenly fired in this piece of code
- duplicate interface declaration for class 'test_coredataAppDelegate'
- redefinition of 'struct test_coredataAppDelegate'

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface test_coredataAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

///////////////////New parts /////////////////////////
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;

UIWindow *window;
UITabBarController *tabBarController;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;


how to fix that please

Best regards

Answer Source

There are two possibilities:

  • you have two interfaces with the same name. Use Xcode's find in project menu option to find instances of test_coredataAppDelegate. Then rename one of the interfaces
  • somehow you have managed to import the .h file twice. Check to make sure you always use #import and not #include.


A bit more info on #import/#include:

#include blindly includes the file at the location of the #include statement. This means that if you #include a file twice in your .m you will get two copies of the file. Almost all traditional C #include files have something like the following bracketing all the content:

// some_file.h
#if !defined SOME_FILE_H
#define SOME_FILE_H

//  entire content of #include file


The above is sometimes referrwed to as an include guard macro.

In Objective-C, if you #import a file, a check is performed by the compiler to make sure it has not already been imported. Consequently the guards are usually omitted. So if you #include a file that was supposed to be #imported, neither check will be done and you will sometimes get duplicate definitions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download