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 trialJay Mayu
6,805 PointsWhere 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
Courses Plus Student 29,439 PointsWhen 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
6,805 PointsJay Mayu
6,805 PointsIt makes sense now. Thanks for the answer.