阅读背景:

声明和使用全局变量_计算机学习园_msp430定义全局变量

来源:互联网 
全局变量历来就是很好的东西,能够在开发中带来很多方便,下面来介绍一下iPhone中软件开发时全局变量的使用方法:

一、新建Constants.h文件(文件名根据需要自己取),用于存放全局变量;

二、在Constants.h中写入你需要的全局变量名,例如:
Object-C代码NSString *master_url;//指针类型int count;//非指针类型

注意:在定义全局变量的时候不能初始化,否则会报错!

三、在需要用到全局变量的文件中引入此文件:
Object-C代码#import "Constants.h"  

四、给全局变量初始化或者赋值:
Object-C代码extern NSString *master_url;  master_url = [[NSString alloc] initWithFormat:@"https://www.wuleilei.com"];//指针类型;需要allocextern int count;count = 0;//非指针类型

五、使用全局变量:和使用普通变量一样使用

 

 
[UIAppcation  sharedApplication].delegate.name = @"";
*AppDelegate *appDelegate = (*AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate。name = @"王成"; 全局变量历来就是很好的东西,能够在开发中带来很多方便,下面来介绍一下iPhone中软件开发时全



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: