据我所知,如果ClassA需要包含ClassB头,ClassB需要包含ClassA头,以避免任何循环包含,则应该使用前向类声明.我也知道#import
是一个简单的ifndef
,所以包含只发生一次.
我的问题是:何时使用#import
,何时使用@class
?有时,如果使用@class
声明,我会看到一个常见的编译器警告,例如:
warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.
我真的很想理解这一点,而不是仅仅删除@class
forward声明,然后抛出#import
来消除编译器给我的警告.