I would like the view controller to be able to access dog in the app delegate.
I would like the app delegate to be able to access mouse in the view controller.
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
int mouse; // <----------------
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
mouse = 12; // <-------------------
NSLog(@"viewDidLoad %d", dog); // <---------------
}
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
int dog; // <---------------
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"applicationWillResignActive %d", mouse); // <--------------
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
dog = 77; // <---------------------
NSLog(@"applicationDidBecomeActive");
}
Part 1:
In the ViewController.h:
In the ViewController.m, add this method:
To access mouse from AppDelegate, use self.viewController.mouse
For example;
Part2:
In the AppDelegate.h:
In the AppDelegate.m, add this method:
In the ViewController.m:
To access dog from ViewController, use this: