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 Playlist Browser with Objective-C Managing Playlist Data Class Initialization

Global constants question

Couldn't we have declared them all in the header file only along with their values? Instead of having declared them in the implementation and then making them accessible in the header file?

1 Answer

Rashii Henry
Rashii Henry
16,433 Points

Declaring those classes within the header file is a common practice and fine. The header file (also known as the interface) is where you want to declare your variables. Simply because inside of your header file you're basically saying, 'Im giving you all the tools to work with'.

Then your implementation takes these tools (the ones that you gave it to work with), so it can implement, or work with those tools the way you intend for them to work.

To answer your question, we could have only declared them in the header file and made them accessible globally. However, the same variables that were declared and initialized within the implementation, needed to be used privately within that same class. So, in those dictionaries we wanted to pass in STATIC VARIABLES into the dictionary and NOT string literals.