title: Unable to update singleton properties
body: <p>I've encountered a stupid problem, and I've tried almost everything (bought 3 books, went through the whole google :)) but nothing helped. And it seems to me like the solution should be extremely simple...</p>
  
  <p>I need to declare a singleton in Objective-C (for an iOS app, if that matters), and it should have some properties that I need to update from other classes. But I can't do that - the properties just won't update, they have the same values set in the "init" method.</p>
  
  <p>I've created a simple app to test out this problem. That's what I've done:</p>
  
  <p>First, I've declared a sample class and its subclass that I'm going to use as a singleton's property:</p>
  
  <pre><code>@interface Entity : NSObject
  
  @property (nonatomic, strong, readwrite) NSMutableString * name;
  
  @end
  
  @implementation Entity
  @synthesize name;
  
  @end
  
  @interface Company : Entity
  
  @property (nonatomic, strong, readwrite) NSMutableString * boss;
  @property (nonatomic) int rating;
  
  @end
  
  @implementation Company
  @synthesize boss, rating;
  
  @end
  </code></pre>
  
  <p>Then I declare the singleton itself based on the method described in the "iOS Programming Guide by Big Nerd Ranch" book. I'm using both my custom class and a standard NSMutableString as properties, just for clarity's sake:</p>
  
  <pre><code>@class Company;
  
  @interface CompanyStore : NSObject
  {
       NSMutableString * someName;
  }
  
  @property (nonatomic, strong, readwrite) Company * someCompany;
  @property (nonatomic, strong, readwrite) NSMutableString * someName;
  
  + (CompanyStore *) store;
  - (void) modifyCompanyProperties;
  
  @end
  
  @implementation CompanyStore
  @synthesize someCompany, someName;
  
  // Declaring the shared instance
  + (CompanyStore *) store
  {
      static CompanyStore * storeVar = nil;
  
      if (!storeVar) storeVar = [[super allocWithZone:nil] init];
  
      return storeVar;
  
  }
  
  // Replacing the standard allocWithZone method
  + (id) allocWithZone:(NSZone *)zone
  {
      return [self store];
  }
  </code></pre>
  
  <p>Then I initialize all the properties with initial values:</p>
  
  <pre><code>- (id) init
  {
      self = [super init];
      if (self) {
          someCompany = [[Company alloc] init];
          [someCompany setBoss:[NSMutableString stringWithFormat:@"John Smith"]];
          [someCompany setName:[NSMutableString stringWithFormat:@"Megasoft"]];
          [someCompany setRating:50];
  
          someName = [[NSMutableString alloc] initWithString:@"Bobby"];
      }
      return self;
  }
  </code></pre>
  
  <p>And from another class (view controller that displays the contents in a view):</p>
  
  <p><b>1.</b> I get the values of the singleton's properties. Everything's okay - I get "John Smith", "Megasoft", "Bobby" and 50 for my int value. The values from my <b>init</b> method.</p>
  
  <p><b>2.</b> I change the singleton's properties from that view controller (using several ways - I'm not sure now which one is right):</p>
  
  <pre><code>- (IBAction)modify2Button:(id)sender {
  
      CompanyStore * cst = [CompanyStore store];
  
      NSMutableString * name = [[NSMutableString alloc] initWithString:@"Microcompany"];
      NSMutableString * boss = [[NSMutableString alloc] initWithString:@"Larry"];
  
      [[[CompanyStore store] someCompany] setName:name];
      cst.someCompany.boss = boss;
  
      NSMutableString * strng = [[NSMutableString alloc] initWithString:@"Johnny"];
      [cst setSomeName:strng];
  }
  </code></pre>
  
  <p>... and then I'm trying to get the values again. I'm still getting the old set - "John Smith", "Megasoft" etc. even though when I set a breakpoint at one of the strings, I can see that singleton's name property is "Microcompany" and not "Megasoft" at the time of the break... But it doesn't seem to be assigned.</p>
  
  <p><b>3.</b> Then I'm trying another thing - I'm calling from the view controller a singleton's private method, which assigns another set of values to the properties. This is that method in the singleton:</p>
  
  <pre><code>- (void) modifyCompanyProperties
  {
      NSMutableString * boss = [[NSMutableString alloc] initWithString:@"George"];
      NSMutableString * name = [[NSMutableString alloc] initWithString:@"Georgeland"];
  
      [someCompany setBoss:boss];
      [someCompany setName:name];
      [someCompany setRating:100000];
  
      [someName setString:@"Nicholas"];
  
  }
  </code></pre>
  
  <p><b>4.</b> I'm trying to get the updated property values from the view controller again... and still get those "John Smith", "Megasoft"... Nothing changes.</p>
  
  <p>It seems like the properties of the singleton are set only once and then I can't change them, even though their attributes are declared as "readwrite".</p>
  
  <p>It looks like I don't understand something simple.
  If someone could explain how to correctly declare and update properties in singletons, I would be very grateful.</p>