問題:
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