Shoot me! (Question about objects/classes)

Discussion in 'iOS Programming' started by Delta-NC, Mar 3, 2009.

  1. macrumors member


    Apr 22, 2008
    Scotland, European Union
    So I started putting together an app to do a few basic sums, it has the basic AppDelegate and ViewControler classes and I also created a new class to store my data.

    How on Earth do I reference my data object from the view controller? I thought I would be referencing it through the AppDelegate but everything i try just fails to work. I figure I've completely missed the point somewhere.

    Objective-C hates me! :D
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
  3. macrumors 6502

    Oct 31, 2007
    San José
    Maybe in your ViewController class, try something like:

    myViewControllerDataModel = [(CustomAppDelegate *)[[UIApplication sharedApplication] delegate] myAppDelegateDataModel];

    You are telling the main application to return its delegate, which is an instance of CustomAppDelegate. CustomAppDelegate has a method called myAppDelegateDataModel that returns a DataModel. Make sure you tell your app that your delegate will be a CustomAppDelegate (and it will have the myAppDelegateDataModel method), or you might have a warning that says it will not respond to myAppDelegateDataModel.

    All in all though, I'm also not too sure that using your appDelegate to store data models is the best way to go. I would leave it in my CustomViewController.

Share This Page