warning: duplicate protocol definition of '…' is ignored

陌路散爱 提交于 2019-11-29 04:37:53

Check to make sure you don't have the header file added in your project twice, or two different files that both implement the protocol. This is what caused the warning to appear for me.

Yes I had the same problem. I was unable to find the duplicate header file in Xcode project. But when i went through the finder from the Xcode i found the 2 header file of the protocol in the project. Deleting one solved the problem. Thanks.

Just to supplement the existing answers here with the specific problem I encountered.

Basically, the compiler isn't lying. It is finding more than one definition of a class, protocol, enum, define, or whatever exists in the offending header files.

The fault could be a combination of your header files and the header search path.

At first, the issues seem puzzling as we know that the statement #import will only import files that have not already been implemented. Therefore, unlike #include, this problem shouldn't happen, right?

#import does work. However, if your headers have been set up incorrectly then although it may encounter a file with the same name, e.g. MyLibrary.h, if that file exists in two different places both of which are in the header search path then Xcode will perceive those as two different files.

In my case, I had a static library build phase which copied public headers.

The dependent products searched the folder above - defined in Build Settings as include/$(TARGET_NAME) - and the source folder of my project.

That meant two different folders - both in the header search path - that contained the file MyLibrary.h. Everything in that file would cause a duplicate or redefinition compiler warning or linker error.

TLDR: the same file may be in two different folders and both are in your header search path. Check your paths, and if you've incorporated a static library into the project or workspace, also check where the public headers are copied to as part of your investigation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!