Initializing Booleans

I have a globals method that I use to keep track of global values in my apps. It is mostly for options. I override the getter like this. In this example, if trials per round is not set, I initialize it to the #defined value for that app.

- (NSUInteger)trialsPerRound {
    if ( !_trialsPerRound ) _trialsPerRound = TRIALS_PER_ROUND;
    return _trialsPerRound;

I tried to do the same thing for some Booleans, but ran into a problem.

- (BOOL)reviewIgnored {
    if ( !_reviewIgnored ) _reviewIgnored = YES;
    return _reviewIgnored;

I wanted the reviewIgnored value to start at YES if it was not set. But what happened is that when I would change it to NO in the options page it would be fine. But when I called it in my if statement

  if (![Globals sharedInstance].reviewIgnored) {

what happened is that the getter checks its value, sees that it is NO. The if statement says to change reviewIgnored to YES and I get the wrong behaviour.

What I did was put all of my Boolean initialization in th AppDelegate.m file. Problem solved.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.