可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
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.
回答2:
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.
- Clean project(s)
- Delete the "Derived Data" (Organizer > Projects tab, select the project and click Delete)
- Restart Xcode
- Build
回答3:
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 ...
回答4:
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.
回答5:
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".
回答6:
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
回答7:
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.
回答8:
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.
回答9:
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.
回答10:
Had same issue, seemed that I had one too many class.m files in my project.pbxproj file.
Always back up that file before editing it just in case!
回答11:
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. !!
回答12:
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.
回答13:
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.