xcode 警告:“...”的重复协议定义被忽略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8138689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
warning: duplicate protocol definition of '...' is ignored
提问by Elliot
How should I respond to this warning?
我应该如何回应这个警告?
warning: duplicate protocol definition of '...' is ignored
警告:“...”的重复协议定义被忽略
My protocol declaration is in its own .h file, and it is #import'ed in a few other files in my project.
我的协议声明在它自己的 .h 文件中,它在我的项目中的其他几个文件中被#import。
Well, just in case, here's the entire header file with the protocol declaration:
好吧,为了以防万一,这里是带有协议声明的整个头文件:
#import <Foundation/Foundation.h>
@class Wrapper;
@protocol WrapperDelegate
@required
- (void)wrapper:(Wrapper *)wrapper didRetrieveData:(NSData *)data;
@optional
- (void)wrapperHasBadCredentials:(Wrapper *)wrapper;
- (void)wrapper:(Wrapper *)wrapper didCreateResourceAtURL:(NSString *)url;
- (void)wrapper:(Wrapper *)wrapper didFailWithError:(NSError *)error;
- (void)wrapper:(Wrapper *)wrapper didReceiveStatusCode:(int)statusCode;
@end
Thanks for any advice.
感谢您的任何建议。
采纳答案by Elliot
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.
检查以确保您的项目中没有两次添加头文件,或者两个不同的文件都实现了该协议。这就是导致我出现警告的原因。
回答by user1874641
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.
是的,我遇到了同样的问题。我无法在 Xcode 项目中找到重复的头文件。但是当我通过 Xcode 查找 finder 时,我在项目中找到了协议的 2 头文件。删除一个解决了问题。谢谢。
回答by Max MacLeod
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
只会导入尚未实现的文件。因此,不像#include
,这个问题不应该发生,对吧?
#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 paththen Xcode will perceive those as two different files.
#import
确实有效。但是,如果您的标头设置不正确,那么尽管它可能会遇到同名的文件,例如MyLibrary.h
,如果该文件存在于两个不同的位置,并且都在标头搜索路径中,那么 Xcode 会将它们视为两个不同的文件.
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)
- andthe source folder of my project.
依赖产品搜索上面的文件夹 - 在构建设置中定义为include/$(TARGET_NAME)
-以及我的项目的源文件夹。
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.
这意味着包含该文件的两个不同文件夹 - 都在标题搜索路径中MyLibrary.h
。该文件中的所有内容都会导致重复或重新定义编译器警告或链接器错误。
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.
TLDR:同一个文件可能位于两个不同的文件夹中,并且都在您的标题搜索路径中。检查您的路径,如果您已将静态库合并到项目或工作区中,还要检查公共头文件复制到的位置作为调查的一部分。