views:

163

answers:

1

My Problem is this:

  • My framework contains public and private headers - the public headers import private headers in the framework
  • My app that links against this framework imports public headers

Now when I compile it, XCode complains about missing files (the private headers that are indirectly imported via the frameworks public headers). I read somewhere on stackoverflow that I should do this:

"In the public header file use @class to include other interfaces and use #import in the implementation file (.m)."

I find this solution pretty unsatisfying - you have to use it for circular dependencies, too. Is there any better way to keep my headers private?

A: 

To get about circular references use the @class directive in the header and the #import in the source file.

In OtherClass.h:

@class MyClass;
@interface OtherClass
{
    MyClass *myInstance;
}
@end

In OtherClass.m:

#import "OtherClass.h"
#import "MyClass.h"
@implement OtherClass
@end

In MyClass.h:

@class OtherClass;
@interface MyClass
{
    OtherClass *otherInstance;
}
@end

In MyClass.m:

#import "MyClass.h"
#import "OtherClass.h"
@implement MyClass
@end
Andrew Hooke
Thanks for the elaborate example, but this @class declaration is exactly what I find unsatisfying (see comment above)
darklight
Don't get me wrong, this is a good and valid solution, but I was asking for a "cleaner" solution than this - or if there is any :)
darklight