Search code examples
objective-ciosxcodesparrow-framework

"Cannot find interface declaration for NSObject"?


So I've done some research into this issue, but I haven't found anything similar just yet...

So I'm coding a game in Obj-C using Xcode and Sparrow Framework. I've been working on the simulator up until this point, and it's all been going fine. But when I switch to running it on my device, I get all sorts of errors for things that should be standard, e.g. "Cannot find interface declaration for NSObject", "Unknown type name 'NSMutableArray'" etc. I've already got #import in each class, so you would think that it shouldn't happen, right? I get the feeling that it's just a line or two that needs changing somewhere - but I haven't got a clue what or where.

If anyone has any advice, it would be very much appreciated. :)

EDIT: Here's a screenshot of one of the .h files that give errors - it seems to only be in some of the .h files that I've created. https://i.sstatic.net/H04mE.png


Solution

  • It sounds like you may have a circular reference in one of your header files.

    This can happen when foo.h #imports "bar.h" and bar.h #imports "foo.h" (or sometimes its a chain of three or more header files importing each other in a circle) and it leads to spurious errors like the one you're seeing.

    The solution is to try to avoid importing headers in your .h files, and instead use @class references for external classes in the .h files and put the #imports in the .m files instead. So instead of writing:

    #import "SomeClass.h"
    

    In your .h files, whenever possible put:

    @class SomeClass;
    

    In your .h file, and put the #import statement in your .m file instead.