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 Build a Simple iPhone App with Objective-C Creating a Data Model Refactoring Into a Model

Ocky Wiemeijer
Ocky Wiemeijer
5,451 Points

Why is '@class FactBook' used instead of importing the class header for FactBook?

Why only import FactBook.h in the implementation file of ViewController (ViewController.m) and not in ViewController.h?

2 Answers

There is a programming rule in OOP called forward declaration. This is what Michael meant. FD is used if you want to reference a property, but use it later in the program. Its a good paradigm to promise to the compiler "Hey Compiler, i know you want always a definition of a property, but here is a property and I promise that this property will be DECLARED when you need it"

hope that helps for better understanding Thorsten

Michael Vilabrera
PLUS
Michael Vilabrera
Courses Plus Student 11,252 Points

consider the @class as an IOU for the compiler. since the .h file does not create any objects, the @class will reserve space for a pointer. inside the .m we will need to use the #import directive to create the pointer for the object, so we must use #import.

answer is in greater detail here: http://stackoverflow.com/questions/322597/class-vs-import