In Class A
a.m. defines a global variable of Class A
#import "A.H" nsstring* [email protected] "HelloWorld"; @implementation a//nsstring* [email protected] "HelloWorld";
Two places, anyway, is defined as a global externally accessible variable of such a class.
In Class B
B.M inside this definition
#import "A.h" #import "b.h" extern nsstring* hello; @implementation b
Then you can use Hello in class B, and the value of Hello is directly @ "HelloWorld";
When we do the project, we can define a Config.h
#ifndef cfg#define cfg NSString *url = @ "www.baidu.com"; #endif
Initializing URLs in APPDELEGATE.M
#import "AppDelegate.h" #import "Config.h" extern NSString* url; @implementation AppDelegate- (BOOL) application: (uiapplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; // override point for customization after application launch. self.window.backgroundColor = [UIColor whitecolor]; [self.window makekeyandvisible]; nslog (@ "%@", url); //output www.baidu.com url = @ "www.google.com"; //change the value of Hello return yes;}
Then other similar appdelegate like extern hello
Add extern before declaring variables in iOS