Add extern before declaring variables in iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.