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:06

I also had this exact issue while archiving a workspace with a variety of self created static libraries. The project would build fine and run on the simulator but when I attempted to 'Archive' the build for AdHoc testing, I would receive these duplicate interface definition errors. The resolution was for me to make sure that the 'Copy Headers' phase was correctly indicating the public/project/private headers. I had one header file that was set to 'project' erroneously. It needed to be 'public' and after that, the archive was created successfully.

查看更多
Ridiculous、
3楼-- · 2020-02-10 03:08

My problem was following. I added pop animation framework to my project but using xcodeproj instead of xcworkspace. After configuration I was able to build pop-iso-framework target but I was unable to build my app target. Later I realised that Xcode has added pop classes to Build Phases -> Compile Sources of my app target. Deleting all pop classes from there fixed the problem.

查看更多
狗以群分
4楼-- · 2020-02-10 03:10

I had this issue when using two versions A.h A.m files each for different target. So I made two folders (physical directories) and kept each A.h and A.m in separate folder. Then added folder to the required target. Solved the issue for me.

Bit out of context but might help. !!

查看更多
对你真心纯属浪费
5楼-- · 2020-02-10 03:21

I had this same problem building a framework. The "previous definition is here" error pointed to exactly the same header file and line number as the original "duplicate interface definition for class" error. None of the above worked, and there were no errors in the code. I did a Spotlight search for the implicated header, and two copies showed up: the one I expected, and another in build/Debug-iphonesimulator/include. I did a clean and then manually deleted the build directory. The problem went away.

查看更多
We Are One
6楼-- · 2020-02-10 03:22

I changed from "#include" to "#import" in all file headers and it solved the problem. I suppose that when you "#include" a file, you need to write your own guards against multiple inclusions, while XCode handles it for you when you use "#import".

查看更多
女痞
7楼-- · 2020-02-10 03:23

For me this issue was caused when I was migrating to use_frameworks! on Cocoapods. I was importing a header from the FBSDKCoreKit in a convenience class I used to extend the methods. This was fine until I switched to using frameworks, when using a local includes (#import "FBSDKAccessToken.h") is no longer OK; I had to switch to global includes (#import <FBSDKCoreKit/FBSDKAccessToken.h>). This article describing why you don't include headers in your bridging file anymore pointed me in the right direction.

查看更多
登录 后发表回答