2014年7月13日 星期日

[iOS] Objective-c sharedApplication delegate, global @property



AppDelegate.h

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


@property (nonatomic, assign)NSInteger globalCount;


How to use?

yourViewController1.h

#import "AppDelegate.h"

yourViewController1.m

- (void)functionSet {

       appDelegate. globalCount = 123;
}

ViewController2.h

#import "AppDelegate.h"


ViewController2.m

- (void)functionRead {

    NSLog(@"globalCount: %d"appDelegate. globalCount);
   // $ globalCount: 123
}

沒有留言:

張貼留言