You could do what is suggesting, add a variable in AppDelegate and then fetch it from your view controllers like this:
AppDelegateNeme *ap = (AppDelegateNeme *)[[UIApplication sharedApplication] delegate];
ap.yourVar = smth
As you can see in code above, you are accessing shared instance of UIApplication and just by casting it to your AppDelegate class you can reach your "global" variable. But I personally don't see this as the best solution. What happens is that you need to include your app delegate in every UIViewController, and chances are that you already included that UIViewController in your AppDelegate so you could end up looking at recursive includes or a very messy code.
Cleaner approach would be to create a class to store your global variables, just add a file and for a class choose NSObject. Then you can create singleton object of that class or you can just define class variables and class methods (the one with +) to store and fetc values from your "global vars".
In this way your code will be mode readable and you will never have any include problems, as long as you don't start including stuff in that class.
Example:
//GlobalClass.h
@interface GlobalClass : NSObject
@property (nonatomic) BOOL someBool;
// example wit a singleton obj:
+ (GlobalClass *)globalClass;
// example with class methods
+(int)GetMyVar;
+(void)SetMyVar:(int)var;
//GlobalClass.m
static int MyVar;
@synthesize someBool;
static GlobalClass *globalClass = nil;
+ (GlobalClass *)globalClass
{
if (globalClass == NULL)
{
// Thread safe allocation and initialization -> singletone object
static dispatch_once_t pred;
dispatch_once(&pred, ^{ globalClass = [[GlobalClass alloc] init]; });
}
return globalClass;
}
+(int)GetMyVar
{
return MyVar;
}
+(void)SetMyVar:(int)var
{
MyVar = var;
}
So from outside (from your viewcontroller):
To create singleton and set our bool property:
//set var:
[[GlobalClass globalClass] setSomeBool:YES];
// get
BOOL b = [[GlobalClass globalClass] someBool];
OR use class methods (don't need to create singletone obj)
// set
[GlobalClass SetMyVar:5];
// get
int num = [GlobalClass GetMyVar];
Hope this helps...