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.
(据我了解,如果ClassA需要包括ClassB标头,而ClassB需要包括ClassA标头,以避免任何循环包含,则应使用前向类声明。)
I also understand that an#import
is a simple ifndef
so that an include only happens once. (我也理解#import
是一个简单的ifndef
因此一个include仅发生一次。)
My inquiry is this: When does one use #import
and when does one use @class
?
(我的查询是:什么时候使用#import
和何时使用@class
?)
@class
declaration, I see a common compiler warning such as the following: (有时,如果我使用@class
声明, @class
看到常见的编译器警告,例如:)
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.
(真的很想了解这一点,而不是仅仅删除@class
前向声明,然后抛出#import
来使编译器向我发出的警告静音。)