Duplication of interface error in xcode

2019-09-16 03:16发布

问题:

I am not even sure how to start. I am developing an iPhone application with the latest Xcode and sdk using core plot and the core async socket library. Everything was fine until a few hours ago, when Xcode dumped a ton of "interface duplication" errors for no apparent reason.
The two files that are emitting errors are the AsyncSocket.h and an API client that I wrote in order to get data out of the target server.
The errors are the following:

  • Nested Redefinition error on all enums in AsyncSocket.h and my API client.
  • Redeclaration of enum on all enumerations in AsyncSocket.h and my API client.
  • Duplicate interface declaration on the AsyncSocket.h and the API client's interface file.
  • The error occurred between two builds of the application. NOTHING was changed during that time which is why I can't even begin to think what is causing this.

The API client is a really simple thing, it just uses the async socket to send queries to the server and then return the parsed results in arrays. Nothing complicated, as I am not that into objective c yet.
I wish I could give some more useful information but that is all I have.

回答1:

i believe your problem results from a simple mistake. In the header file you begin with:

@interface ClassName : SuperclassName

while in the .m file you do:

@interface ClassName ()

When you forget the brackets, the compiler complains.

I hope this helps. Best wishes with your app.



回答2:

I had this problem and the response above put me on the right track.

I created a new enum record in a .h file I use for all my Constants.

But I forgot to add the semi-colon on the end. This simple little syntax error resulted in some weird and confusing errors appearing on files other than the one which contained the error.

No doubt you've resolved this by now but it might fix someone else's issues in the future.



回答3:

I also experienced the "Duplicate interface definition" error message and traced it to my having put an "#include xxx.h" in a header (.h) file instead of in the .m file where I intended to put it.