In reference to the answer of this SO question: Keeping track of changes in a UIView
I need help setting up the global aspect of the NSMutableSet. In my appdelegate.h file I’ve got this:
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ViewController *viewController;
NSMutableSet *statesTouched;
}
and this in my appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
statesTouched = [[NSMutableSet alloc]init];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
In my viewcontroller.h file I’m adding the object like this:
[statesTouched addObject:touchedStateName];
but I’m getting an undeclared identifier for statesTouched. I’ve never tried putting something like this into my app delegate and I’m a little confused at how this should be working. Thanks!
This is because is an instance variable of your
AppDelegate, not your view controller. If you move the declaration and the initialization to your view controller, the error will go away. It would not make it a global variable, though, which is good if it works for you.If it does not work for you, make the variable a truly global one: move the declaration out of the app delegate, and add
externkeyword, like this:Now add the definition in the .m file, like this:
Make sure the definition is outside the
@implementationblock.