title: Objective C - sample Singleton implementation
body: <p>*<em>I definitely need a break... cause was simple - array was not allocated... Thanks for help. Because of that embarrassing mistake, I flagged my post in order to delete it. I do not find it useful for Users ;) *</em></p>
  
  <p>I have just tried to create a singleton class in iOS, but I probably I am making a mistake. Code (no ARC is a requirement):</p>
  
  <pre><code>#import "PeopleDatabase.h"
  #import "Person.h"
  
  #import &lt;Foundation/Foundation.h&gt;
  
  @interface PeopleDatabase : NSObject{objetive
      NSMutableArray* _arrayOfPeople;
  }
  
  +(PeopleDatabase *) getInstance;
  
  @property (nonatomic, retain) NSMutableArray* arrayOfPeople;
  
  
  @end
  </code></pre>
  
  <p>--</p>
  
  <pre><code>    @implementation PeopleDatabase
      @synthesize arrayOfPeople = _arrayOfPeople;
  
      static PeopleDatabase* instance = nil;
  
      -(id)init{
          if(self = [super init]) {
              Person* person = [[[Person alloc] initWithName:@"John" sname:@"Derovsky" descr:@"Some kind of description" iconName:@"johnphoto.png" title:Prof] retain];
  
              [_arrayOfPeople addObject:person];
              NSLog(@"array count = %d", [_arrayOfPeople count]); // &lt;== array count = 0 
              [person release];
          }
          return self;
      }
  
      +(PeopleDatabase *)getInstance {
          @synchronized(self)
          {
              if (instance == nil)
                  NSLog(@"initializing");
                  instance = [[[self alloc] init] retain];
                  NSLog(@"Address: %p", instance);
          }
          return(instance);
      }
  
      -(void)dealloc {
  
          [instance release];
          [super dealloc];
      }
  @end
  </code></pre>
  
  <p>When invoking getInstance like here:</p>
  
  <pre><code>PeopleDatabase *database = [PeopleDatabase getInstance];
  NSLog(@"Adress 2: %p", database);
  </code></pre>
  
  <p>Address 2 value the same value as in getInstance.</p>