Welcome to the Treehouse Community
Looking to learn something new?
Dan Boyle2,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.
- We declare the predictions object... but it's empty.
- 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];
Stone Preston42,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.
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.