Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot find interface declaration for <class>"

Screenshots

I'm having quite a hard time setting up a category on a class I made. From what I've read, Objective-C allows you to create a category on any class, not just closed-source ones. (It honestly wouldn't make sense any other way.)

Of course I can add the category messages to the actual class file, but I want to keep them separate (as the category is an uncommonly special use of a class that can be used very generally). I want to share the class, but keep the category private... anyway.

I've stripped down the category to just show the issue at hand. I (currently) get four errors on the first category message. The number of errors I receive on that line is directly proportional to how many times it is references, but it is not an even rise. Does anyone know what could be causing this?

like image 238
Sean Allred Avatar asked Jun 13 '12 20:06

Sean Allred


1 Answers

Your Resources.h file, which is imported by ByteCollection.h, imports ByteCollection+words.h. So when ByteCollection+words.h imports ByteCollection.h, this results in a circular dependency†. The simplest way to break a circular dependency is to move one of the imports to the implementation file rather than the header. It looks like this should be possible with Resources.h.

† You might be wondering, why is it a problem if you have a circular dependency? Well, the #import directive literally just textually includes the file you specify, just like if you copy-pasted. It also intelligently doesn't include a file twice, because that would create duplicate code. But this means that when File A says "I want File B to go before me" and File B says "I want File A to go before me," one of them is going to be disappointed, and that leads to errors like the one you're getting here.

like image 158
Chuck Avatar answered Sep 20 '22 12:09

Chuck