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 trial

iOS Objective-C Basics (Retired) Introduction to Objective-C Composition

include.h vs @class

Will there be a difference when I say to a class on top:

include "Shape.h"

than to say

@class Shape.h;

Is there a difference in functionality?

2 Answers

Yes when you use @class Shape.h you are telling the compiler.. "Hey just make sure this class exists, but don't import it in" This method saves memory and doesn't slow down the application. @class is used inside of .h files because this way you can just check the class without using the actual methods. (Maybe you want to declare a property from a class)

When you use include "Shape.h" you are telling the compiler.. "Hey.. make sure this class exists and import everything in". This is mostly used at the top of .m files because that is where you need the imported class's methods.

Any other questions just ask! I actually asked a similar question like this on these forums a while ago.. but ask away if you need help!

is the @class just pointing to the class in memory so the compiler knows where to grab the reference?

Michael Bowen yup! that is essentially what it does. Points to it

Alex, this makes a lot of sense now! I guess from a memory usage perspective it can be handy.

Thanks!

Mauricio,

No problem! I struggled more with the concept than you did. Good luck with your studies! Let me know if you have any more questions!