title: AppDelegate Being accessed from different classes, from RootController.m
body: <p>My problem is in getting the information from a controller(which happens to be my rootViewController) to another view. In trying to get access to it through the app delegate, I was not able to get it working. I have found how to do this, but this inturn created another problem of getting the view inside a modal view controller to actually display the data. Below I have posted both the appDelegate information, and an NSMutable Dictionary solution code for those that may need help too.</p>
  
  <p>I had tried for more than a week to solve ths problem on my own. My issue ended up being how to access the appDelegate, which was why I was having a problem with the NSDictionary. So in the end the issue wasn't the NSDictionary, although had I gone further it would have been a problem I am sure. </p>
  
  <p>Firstly I would like to thank TechZen for helping me to see I was over programming, and point me in the right direction.</p>
  
  <p>Here is what I learned.</p>
  
  <p>Assign your variable in the appDelegate.</p>
  
  <p>AppDelegate.h</p>
  
  <pre><code> @interface AppDelegate : NSObject  &lt; UIApplicationDelegate, UINavigationControllerDelegate &gt;
  {   
      UIWindow *window;
      UINavigationController *navController;
  
      // Array to store the Makers Objects
      NSMutableArray *makers;
  
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window; 
  @property (nonatomic, retain) IBOutlet UINavigationController *navController;
  
  @property (retain, nonatomic) NSMutableArray *makers;
  @end
  </code></pre>
  
  <p>AppDelegate.m</p>
  
  <pre><code>    - (void)applicationDidFinishLaunching:(UIApplication *)application 
  {
  
      makers = [[NSMutableArray alloc] init] ;
  }
  </code></pre>
  
  <p>In the ViewController.m assign the variable to the appDelegate. I did this inside a tableView function didSelectRowAtIndexPath.</p>
  
  <pre><code>        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  
  // The line below loads it into the variable, the one above takes it and makes it available for other view Controllers.
  
         Maker *maker = (Maker *)[appDelegate.makers objectAtIndex:indexPath.row];
  
  // the combination of the above and below also loads the information into another array in this view controller, defined in an NSObject Controller called Maker (.h and .m files)
  
        maker = [self.Makers objectAtIndex:indexPath.row];
  </code></pre>
  
  <p>Now in your view Controller you want to load the variable from the appDelegate, set it up like this.</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  #import "AppDelegate.h"
  #import "Maker.h"
  
  @class AppDelegate;
  
  @interface DetailsViewController : UIViewController
  {
  
          AppDelegate *dappDelegate;
      DetailsViewController *detailsView;
  
      IBOutlet UITextView *makerDescription;
  
  }
  
  @property (retain, nonatomic) AppDelegate *dappDelegate;
  
  @property (nonatomic, retain) DetailsViewController *detailsView; 
  
  @property (nonatomic, retain) IBOutlet UITextView *makerDescription;
  
  @end
  </code></pre>
  
  <p>and in the viewController.m file;</p>
  
  <pre><code>#import "DetailsViewController.h"
  #import "AppDelegate.h"
  
  @synthesize dappDelegate;
  
  - (void)viewWillAppear:(BOOL)animated // or ViewDidLoad not sure which is better.
  
      dappDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
      NSString *newLocalVariable = [dappDelegate.makers description];
  
  NSLog(@"newLocalVariable: %@", [dappDelegate.makers description]);
  // This is for verifying you have it loaded. 'description' is defined in the Maker NSObject, see below for those files, and above for where it was assigned originally
  </code></pre>
  
  <p>..... and assign it to what ever you want now!</p>
  
  <p>I hope this helps everyone. You could at this point drop the NSArray from there into a NSDictionary, but the access is now with keys and values, so a bit more complicated at this point to access, but of course advantages. I just cannot get that totally down yet, and have backed away from that method to just use a NSArray for now.</p>
  
  <p>Below is a sample of a Makers h and m file for you to see as well.</p>
  
  <pre><code>Maker.h
  
  @interface Maker : NSObject 
  {
      NSString *name;
      NSString *address;
      NSString *city;
      NSString *postalcode;
      NSString *country;
      NSString *phonenumber;
      NSString *email;
      NSString *description;
      NSString *services;
      NSString *website;
  }
  
  @property (nonatomic, copy) NSString *name;
  @property (nonatomic, copy) NSString *address;
  @property (nonatomic, copy) NSString *city;
  @property (nonatomic, copy) NSString *postalcode;
  @property (nonatomic, copy) NSString *country;
  @property (nonatomic, copy) NSString *phonenumber;
  @property (nonatomic, copy) NSString *email;
  @property (nonatomic, copy) NSString *description;
  @property (nonatomic, copy) NSString *services;
  @property (nonatomic, copy) NSString *website;
  
  - (id)initWithName:(NSString *)n address:(NSString *)a city:(NSString *)c postalcode:(NSString *)z country:(NSString *)o phonenumber:(NSString *)p email:(NSString *)e description:(NSString *)d services:(NSString *)s website:(NSString *)w;
  
  @end
  </code></pre>
  
  <p>and its Maker.m file;</p>
  
  <pre><code>#import "ViolinMaker.h"
  
  @implementation Maker
  @synthesize name, address, city, postalcode, country, phonenumber, email, description, services, website;
  
  - (id)initWithName:(NSString *)n address:(NSString *)a city:(NSString *)c postalcode:(NSString *)z country:(NSString *)o phonenumber:(NSString *)p email:(NSString *)e description:(NSString *)d services:(NSString *)s website:(NSString *)w; 
  {
      self.name = n;
      self.address = a;
      self.city = c;
      self.postalcode = z;
      self.country = o;
      self.phonenumber = p;
      self.email = e;
      self.description = d;
      self.services = s;
      self.website = w;
      return self;
  }
  @end
  </code></pre>
  
  <p>I hope this helps others get this straight, as it really cost me a lot of time and I hope you can get a bit from what I learned.</p>
  
  <p>Sincerely, 
  Kirk</p>