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.


Dan Boyle
Dan Boyle
2,978 Points

MVC question on Crystal Ball app

Sorry if some of my terminology is a little off. I'm still getting all of that into place.

In the Crystal Ball app, I completely understand why we create a custom class for the NSArray *predictions.

However, when you're creating the NSArray object, why use an if statement to set the data?

I see how the if works.

  1. We declare the predictions object... but it's empty.
  2. Our if statement checks to see if it's empty and then fills it... or returns it so it can be used.

Why not just set the instance variable with the data?

_predictions = [[NSArray alloc] initWithObjects:@"Data 1", @"Data 2", ...., nil];

3 Answers

Stone Preston
Stone Preston
42,016 Points

because that would set it each and every time you call that method. It only needs to be set once, no need to set it every single time.

Dan Boyle
Dan Boyle
2,978 Points

Okay... I see that now. Thanks!

if statement is applied so that you just have to provide the data and upload that in the memory when the app is launched. After the data is uploaded in the memory the next time you open the app, the time and memory will be saved and the app will be opened and used quickly.