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


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.