@class与#import - @class vs. #import

问题:

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仅发生一次。 app

My inquiry is this: When does one use #import and when does one use @class ? 个人查询是:何时使用#import和什么时候使用@class Sometimes if I use a @class declaration, I see a common compiler warning such as the following: 有时,若是我使用@class声明, @class看到常见的编译器警告,例如: ui

warning: receiver 'FooController' is a forward class and corresponding @interface may not exist. this

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来使编译器向我发出的警告静音。 url


解决方案:

参考一: https://stackoom.com/question/1LvB/class与-import
参考二: https://oldbug.net/q/1LvB/class-vs-import
相关文章
相关标签/搜索