title: Shared instance with global variables
body: <p>Thanks to some previous questions I managed to share global variables in my whole application.</p>
  
  <p>But still I'm wondering if what I've done is a good practice : </p>
  
  <p><strong>GlobalVariables.h</strong></p>
  
  <pre><code>@interface GlobalVariables : NSObject
     @property (nonatomic, retain) NSMutableArray *eventType;
     @property (nonatomic, retain) NSMutableArray *docType;
  
     // Getters of properties
     + (NSMutableArray *) eventType;
     + (NSMutableArray *) docType;
  </code></pre>
  
  <p><strong>GlobalVariables.m</strong></p>
  
  <pre><code>@implementation GlobalVariables
  
  + (id)sharedInstance {
     static GlobalVariables *instance = nil;
     static dispatch_once_t onceToken;
     // Assert that only one instance of this class will be created
     dispatch_once(&amp;onceToken, ^{
         instance = [[GlobalVariables alloc] init];
         // Default values for our shared variables
         NSArray *defaultEvents = @[@"Default",@"Reunion",@"Famille",@"Vacances"];
         NSArray *defaultDocs = @[@"Handwritten Document",@"Business Card",@"Whiteboard",@"Invoice",@"Picture",@"Printed Document",@"Table",@"To Note"];
         [instance setEventType:[NSMutableArray arrayWithArray:defaultEvents]];
         [instance setDocType:[NSMutableArray arrayWithArray:defaultDocs]];
     });
     return instance;
  }
  
  // Getter of eventType property
  + (NSMutableArray *) eventType {
     GlobalVariables *instance = [GlobalVariables sharedInstance];
     return instance.eventType;
  }
  
  // Getter of docType property
  + (NSMutableArray *) docType {
     GlobalVariables *instance = [GlobalVariables sharedInstance];
     return instance.docType;
  }
  
  // Add a new document type to docType property
  + (void)addNewDocType:(NSString*)doc {
     GlobalVariables *instance = [GlobalVariables sharedInstance];
     [instance.docType addObject:doc];
  }
  </code></pre>
  
  <p>As you can see I call <code>sharedInstance:</code> in my getters (and other methods), this way I can access (and modify) my global variables in any other class like this :</p>
  
  <p><strong>OtherClass.m</strong></p>
  
  <pre><code>NSMutableArray *types = [GlobalVariables docType];
  ...
  [GlobalVariables addNewDocType:@"Slide"];
  </code></pre>
  
  <p>Is it acceptable or not ? 
  I know I could get these variables this way :</p>
  
  <p><strong>OtherClass.m</strong></p>
  
  <pre><code>GlobalVariables *sharedVariables = [GlobalVariables sharedInstance];
  NSMutableArray *types = [sharedVariables docType];
  ...
  [sharedVariables addNewDocType:@"Slide"];
  </code></pre>
  
  <p>But it would mean that any other class using these variables should have a GlobalVariables attribute ? </p>