title: Objective-C - Creating pointer to AppDelegate
body: <p>I have a class which makes use of the app delegate, specifically it has an NSUserDefaults property which is being updated from my class.</p>
  
  <p>In my auth class implementation file I'd have :</p>
  
  <pre><code>+ (BOOL) checkUserDefaults {
      AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
  
      if([appDelegate.session objectForKey:@"UserID"] != nil) {
          return TRUE;
      } else {
          return FALSE;
      }
  }
  
  + (void) syncUserDefaults : (NSString *) UserID {
      AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
      [appDelegate.session setObject:UserID forKey:@"UserID"];
      [appDelegate.session synchronize];
  }
  </code></pre>
  
  <p>How would I store this line of code:</p>
  
  <pre><code>AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
  </code></pre>
  
  <p>As a global (to this class), so that I can just write for example <em>[app.session setObject...]</em>?</p>
  
  <p>I could make a function:</p>
  
  <pre><code>+ (AppDelegate *) app
  {
      return (AppDelegate *) [[UIApplication sharedApplication] delegate];
  }
  </code></pre>
  
  <p>And do <code>[[self app].session setObject...]</code>, but say if I'm referencing the "app" function numerous times that would be instantiating the AppDelegate numerous times wouldn't it?</p>