extern,做用在IOS中,爲了使用全局變量。比寫在appDelegate和定義單例方便一些;app
舉例:spa
1.MyExternClass.h添加這個類,並在.m文件添加 代碼 .net
#import "MyExtern.h" @implementation MyExtern NSString *myExternString = @"123"; @end
#import <UIKit/UIKit.h> #import "MyExternClass.h" @interface ViewController : UIViewController extern NSString *oneInstance; @end3. 在引用類ViewController.m
- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"11__%@",oneInstance); oneInstance = @"changeInstance"; NSLog(@"22__%@",oneInstance); } <pre name="code" class="objc"><a target=_blank href="http://http://download.csdn.net/download/u013375242/8335911"><span style="font-size:24px;">Demo下載</span></a>