It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an #import it a simple ifndef so that an include only happens.
My inquiry is this. When does one use #import and when does one use @class? Sometimes if I use a @class declaration, I see a common compiler warning such as the following:
warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.
Would really love to understand this, versus just removing the @class forward-declaration and throwing an #import in to silence the warnings the compiler is giving me.
So, be sure that if you use @class in .h files to import class, you must reminde that you add the #import to the Corresponding .m files.
本文探讨了Objective-C中@class指令和#import指令的区别及使用场景。分析了@class用于前向声明类名以减少编译器处理的代码量,避免循环包含问题的情况。并通过实例解释了何时使用#import而非@class,以避免编译警告。
1万+

被折叠的 条评论
为什么被折叠?



