Duplicate interface declaration for class 'Foo

2020-02-10 02:40发布

I was working on my program, and it seems something in the settings changed. Suddenly I have the error "Duplicate interface declaration for class 'Foo'". It mentions a header file being duplicated but there's only one copy.

Interestingly this is only happening in debug mode, not device mode.

Does anyone have any idea what might be wrong?

I am using Objective-C++ and some static libraries.

13条回答
狗以群分
2楼-- · 2020-02-10 03:24

In my case, the problem came from bringing in files from another project to reuse. I was not careful to "Copy files if needed" in the copy dialog box, and instead of creating new copies in the new project, it referred to the files in the original project. Once I removed the references and re-copied the files correctly, all was OK.

查看更多
Root(大扎)
3楼-- · 2020-02-10 03:28

I had a similar problem, yet I didn't have two copies of the source files. In my case, I had the following situation:

Class A gave the error above and Class B had a property using Class A's type.

The problem was that in Class B I called #import "Class A" in both the .h and the .m file. This caused the problem above in my case. Hope this helps anyone.

查看更多
迷人小祖宗
4楼-- · 2020-02-10 03:29

I found the problem. There were two copies of the header file and XCode got confused.

Now the mystery is how XCode decided to copy these files by itself ...

查看更多
够拽才男人
5楼-- · 2020-02-10 03:31

I had exactly the same problem. I had two copies of the header and had deleted the old one by deleting the reference to it in xcode. There was then only one reference of the header which pointed to the new header file in the project navigator.

After actually deleting the old header from the file system, the problem went away.

It could be a bug in xcode. Maybe sometimes when you delete a reference to a file, part of the reference still remains in the project file.

查看更多
Root(大扎)
6楼-- · 2020-02-10 03:32

I have this error message and I don't have the the duplicate header or duplicate imports. The problem is that I've renamed the header file and Xcode somehow keep them cached, that gives the build error.

I did the following to fix this. Hope it helps those that already tried other answer and still got the errors.

  1. Clean project(s)
  2. Delete the "Derived Data" (Organizer > Projects tab, select the project and click Delete)
  3. Restart Xcode
  4. Build
查看更多
叛逆
7楼-- · 2020-02-10 03:32

This error occurs because of giving same variable name to different objects. This is the error coming after Xcode7.0. So to overcome this issue just Go to Build Setting and search for No Common Blocks and set it NO.

And build again you will not get this error again.

CheersKP

查看更多
登录 后发表回答