• 119046

    文章

  • 803

    评论

  • 12

    友链

  • 最近新加了换肤功能,大家多来逛逛吧~~~~
  • 喜欢这个网站的朋友可以加一下QQ群,我们一起交流技术。

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

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看到常见的编译器警告,例如:

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


解决方案:

参考一: https://stackoom.com/question/1LvB/class与-import
参考二: https://oldbug.net/q/1LvB/class-vs-import

695856371Web网页设计师②群 | 喜欢本站的朋友可以收藏本站,或者加入我们大家一起来交流技术!

0条评论

Loading...


自定义皮肤 主体内容背景
打开支付宝扫码付款购买视频教程
遇到问题联系客服QQ:419400980
注册梁钟霖个人博客