{"id":2005,"date":"2014-11-05T16:33:11","date_gmt":"2014-11-06T00:33:11","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2005"},"modified":"2014-11-05T16:33:22","modified_gmt":"2014-11-06T00:33:22","slug":"initializing-booleans","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2005","title":{"rendered":"Initializing Booleans"},"content":{"rendered":"<p>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.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n- (NSUInteger)trialsPerRound {\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;if ( !_trialsPerRound ) _trialsPerRound = TRIALS_PER_ROUND;\n&nbsp;&nbsp;&nbsp;&nbsp;return _trialsPerRound;\n}\n<\/code><\/pre><\/p>\n<p>I tried to do the same thing for some Booleans, but ran into a problem.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n- (BOOL)reviewIgnored {\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;if ( !_reviewIgnored ) _reviewIgnored = YES;\n&nbsp;&nbsp;&nbsp;&nbsp;return _reviewIgnored;\n}\n<\/code><\/pre><\/p>\n<p>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<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;if (![Globals sharedInstance].reviewIgnored) {\n<\/code><\/pre><br \/>\nwhat 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.<\/p>\n<p>What I did was put all of my Boolean initialization in th AppDelegate.m file. Problem solved.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. &#8211; (NSUInteger)trialsPerRound { &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if ( !_trialsPerRound &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2005\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Initializing Booleans<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-2005","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2005"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2005\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}