In my AppDelegate I have a reference to an NSObject like this:
@interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
MyObjectManager * myObjectManager;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) MyObjectManager * myObjectManager;
I want to access this from my UIViewController, so I do this:
MyAppDelegate * appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
MyObjectManager * myObjectManager = appDelegate.myObjectManager;
maMyArray = [[NSMutableArray alloc] init];
[[appDelegate myObjectManager] findMyStuff:5 foundArray:maMyArray];
//[myObjectManager findMyStuff:5 foundArray:maMyArray];
However, I think I am not understanding the syntax in Objective C correctly because I throw an exception, EXC_BAD_ACCESS. When I look at the values, they seem correct.
Can someone please explain what I am doing wrong?
Thanks
You have to initialize myObjectManager somwhere:
The best place is probably in the
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsmethod.Don’t forget to release it in the dealloc.