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 Diary App Using Core Data Listing Data using NSFetchedResultsController Fetched Results Controller

Jay Mayu
Jay Mayu
6,805 Points

Where to declare new pointers / variables

I see the author declares the variables / pointers in the .m file itself. But in the previous tutorials we learned that .h file is used for declaration.

Is there any reason the instructor keeps on declaring pointers and new variables in the .m file?

1 Answer

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points

When you declare a property in the class header file, and for that matter a method as well, they become available to other classes that include this class. If you declare the properties and methods inside the implementation file they are private to that class and can't be accessed from outside.

The best way is to keep properties that don't need to be accessed inside the implementation file and the ones that need to be accessed in the header file.

Jay Mayu
Jay Mayu
6,805 Points

It makes sense now. Thanks for the answer.