开发者_StackOverflow社区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?
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
精彩评论