View Full Version : Shoot me! (Question about objects/classes)

Mar 3, 2009, 07:46 PM
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

Mar 3, 2009, 08:03 PM
Where do you instantiate your new class?

North Bronson
Mar 4, 2009, 01:46 PM
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.