项目里面访问AppDelegate做全局变量用有好几种方式 

最原始就是 

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

然后 appDelegate.yourMethord,但每个文件里面这么搞几下挺烦的,所以要想办法简略一下

1,有用宏的 

 

#define AppDelegate (YourAppDelegate *)[[UIApplication sharedApplication] delegate]

2,扩展Catogory来访问的 

 

有在UIApplication上扩展,也有NSObject上直接扩展,我觉得后面这个会影响一点效率吧 

3,我选下面这种,直接在AppDelegate上暴露一个Class Methord 了事。 

 

 

(1)static AppDelegate *appDelegate = nil; 

@implementation AppDelegate

(2) 

- ( BOOL)application:( UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary*)launchOptions {

 

        appDelegate = self;

//...... 

}

(3) 

+ (AppDelegate *)delegate{ 

    return appDelegate;

其他上面提到的方式实现可见 http://stackoverflow.com/questions/4141058/short-hand-for-uiapplication-sharedapplication-delegate 这里的讨论