duplicate interface declaration for class 'test_coredataAppDelegate'

51,304

Solution 1

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.

Edit:

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

#endif

The above is sometimes referred 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.

Solution 2

This happen because you have a copy of that resource in your finder. It is not necessary had added it in your project. You should find in your finder the files with the same name and delete the files duplicated.

Solution 3

In my case replacing

#import "Mixpanel.h"

to

#import <Mixpanel/Mixpanel.h>

Resolved the error

Solution 4

I deleted date model class and create new one and issue fixed. also delete from project directory.

Solution 5

I have got the solution for this first copy that file for example video.m is giving this error so copy this file and delete that file and just paste it again and add that file to project again :)

Share:
51,304

Related videos on Youtube

Ali
Author by

Ali

Updated on December 21, 2020

Comments

  • Ali
    Ali over 3 years

    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;
    
    @end
    

    how to fix that please

    Best regards

  • Alyoshak
    Alyoshak over 10 years
    Had somehow copied an extra version of file. Thanks.
  • Robert J. Clegg
    Robert J. Clegg over 9 years
    Did the same mistake had the same file in the project directory twice. Thanks!
  • bcattle
    bcattle over 8 years
    This happened to me. Why in the world would XCode vacuum in files that aren't in the project?
  • Yossi
    Yossi almost 4 years
    I don't see how to "Use Xcode's find in project menu option to find instances of xxx". I am using Xcoder 11.3. No Project menu option...
  • JeremyP
    JeremyP almost 4 years
    @Yossi it's moved since 2011. The "find in project" functionality is now part of the search table in the navigation bar.
  • Yossi
    Yossi almost 4 years
    Hmmm... Didn't notice the messages are from 2011... But we are still here :) "Navigation bar' = the Xcode/File/Edit/... menu?
  • JeremyP
    JeremyP almost 4 years
    @Yossi No, the pane to the left of the main editor window.

Related