Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialfilibertoheiras
3,211 Points#import vs @class
Hi, when creating our classes and import and import them in our ViewController why and when to use #import "myClass.h" or @class myClass, seem to have the same functionality.
In this lesson we used both on .h use @class but on .m used #import.
Thanks for your time!
3 Answers
Stone Preston
42,016 Pointsyou generally use @class in .h files (using @class just lets the compiler know that that class EXISTS, but it doesnt know anything ABOUT it like its methods, properties, etc), then use #imports in .m files which will let the compiler know all the methods and properties that class has in its header file.
you can use #import in both .h and .m , and with a small number of #imports thats fine, however with a lot of them it can slow down the compiler
so if your file just needs to know a class name and nothing about that class (methods properties etc) then you can use @class, if it needs to know its methods and properties you need to import it
However in all the iOS courses ive rarely seen @class used, #import is used almost exclusively as the time saved is minimal in most cases.
filibertoheiras
3,211 PointsOk, so the point of that is CPU and Memory consuming.. I got it, thanks!!
Stone Preston
42,016 Pointsyeah since using import will import that classes header file, as well as any header files the class being imported imports, and so on and so on so it can add up to a lot of imports.
filibertoheiras
3,211 PointsThanks!!