title: Variable in Objective-C Singleton getting reset
body: <p>I created an Objective-C Singleton class. I have a few properties on the class, including a <code>BOOL</code> property. For some strange reason the <code>BOOL</code> variable that I declared "resets" itself to <strong>YES</strong> outside of the scope that is set in.</p>
  
  <p>In the Singleton class's header, the <code>BOOL</code> is declared using <code>@property</code> with the following parameters:</p>
  
  <pre><code>@property (nonatomic, assign, readonly) BOOL shouldCryptData;
  </code></pre>
  
  <p>In the Singleton class's <code>@interface</code> in the implementation, I redefine the same property as <code>readwrite</code> (because I need it to be read only to outside classes, but read / write to my own).</p>
  
  <pre><code>@interface SingletonClassName ()
      @property (nonatomic, assign, readwrite) BOOL shouldCryptData;
  @end
  </code></pre>
  
  <p>The <code>BOOL</code> property gets set during initialization of the singleton class. I am setting it like this inside one of the init methods. There are multiple init methods which specify whether or not data should be crypted or not - this is just <em>one</em> example of where it would be set. Only one of my init methods call super, all the others make a call to the main init.</p>
  
  <pre><code>- (id)init {
      self = [super init];
      if (self) {
          // Brief setup code
  
          [self setShouldCryptData:NO]; // Have also tried using dot-notation and without *self*
          // I can confirm that the shouldCryptData property is NO (within the current scope) right after setting it in this method
      }
      return self;
  }
  </code></pre>
  
  <p>Now, the odd part is that <strong>when I try to access <code>shouldCryptData</code> from any other method, it always returns YES</strong>. Why would it return YES after explicitly setting it to NO? </p>
  
  <p>I'm not accessing it in any strange way, just like this:</p>
  
  <pre><code>if (self.shouldCryptData == YES) // Outside of the init method, this is ALWAYS true
  </code></pre>
  
  <p>I know I'm doing something wrong, but I can't figure it out. I feel like it has something to so with the singleton, but I'm not sure. It seems like neither Google, nor StackOverflow have any answers for this. Any ideas?</p>
  
  <hr>
  
  <p><strong>EDIT</strong> </p>
  
  <p>Singleton implementation:</p>
  
  <pre><code>//-------- Header ---------------------//
  
  @interface SingletonClassName : NSObject
  
  + (SingletonClassName *)sharedManager;
  
  @end
  
  //-------- Implementation ------------//
  
  @implementation
  + (SingletonClassName *)sharedManager {
      static SingletonClassName *sharedManager = nil;
  
      static dispatch_once_t onceToken;
      dispatch_once(&amp;onceToken, ^{
          if (sharedManager == nil) sharedManager = [[super allocWithZone:NULL] init];
      });
  
      return sharedManager;
  }
  
  + (id)allocWithZone:(NSZone *)zone {
      return [self sharedManager];
  }
  
  - (id)copyWithZone:(NSZone *)zone {
      return self;
  }
  </code></pre>