@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
相關文章
相關標籤/搜索