@class vs #import

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

I have seen various tutorials, and only a few use @class, while most others use #import.

+6
objective-c
source share
2 answers

@class does not import the file, it simply tells the compiler "This class exists, even if you do not know about it, do not warn me if I use it." #import actually imports the file so that you can use all the methods and instance variables. @class used to save compilation time (importing the whole file makes compilation take longer). You can use #import if you want, it will take longer for your project.

+14
source share
+6
source share

All Articles