Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
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