开发者

@class vs #import

开发者 https://www.devze.com 2023-01-06 16:17 出处:网络
What is the difference when using @class or #import in objective-c? I have seen various t开发者_运维知识库utorials and only a few use @class while most of the others use #import.@class doesn\'t impor

What is the difference when using @class or #import in objective-c?

I have seen various t开发者_运维知识库utorials and only a few use @class while most of the others use #import.


@class doesn't import the file, it just says to the compiler "This class exists even though you don't know about it, don't warn me if I use it". #import actually imports the file so you can use all the methods and instance variables. @class is used to save time compiling (importing the whole file makes the compile take more time). You can use #import if you want, it will just take longer for your project to build.


See Defining a Class, especially Referring to Other Classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消