iOS 中extern、static修饰变量的使用及define和const区别
来源:互联网 发布:能看地方台的网络电视 编辑:程序博客网 时间:2024/06/04 21:15
(一)extren:外部变量
作用:引用其他类的全局变量
//externViewController.m 全局变量NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";// externViewController.h extern NSString * const AFNetworkingReachabilityDidChangeNotification;
#import "ViewController.h"#import "externViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%@",AFNetworkingReachabilityDidChangeNotification);}
打印结果
2015-10-27 15:04:56.236 extrendemo[1031:91474] com.alamofire.networking.reachability.change
(二)static :内部变量
1、修饰全局变量
作用:static定义的全局变量,extren引用依然获取不到其值
2、修饰局部变量
作用:某个函数调用频率比较高并且某个变量值固定不变可以使用。
- (void)viewDidLoad { [super viewDidLoad]; [self test]; [self test]; [self test];}-(void)test{ static int PI = 3.14; NSLog(@"%d",PI); PI = PI + 1;}
(三)define与const的使用
1、define:预处理指令,在编译之前替换宏值,运行中有几个宏就开辟几个临时内存空间, 适用于传入多个变量
#define AYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
2、const:只用一份内存,适用于只有一个变量且不允许修改
//externViewController.mNSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";// externViewController.hextern NSString * const AFNetworkingReachabilityDidChangeNotification;
0 0
- iOS 中extern、static修饰变量的使用及define和const区别
- static、const、extern和define的区别
- c语言变量和函数声明的修饰符static,extern,#define,const
- extern,static,const修饰变量的用法
- iOS开发const,static,extern,#define的使用
- ios中static和extern的区别
- extern和static修饰全局变量的区别
- # IOS 对 static extern const #define 的理解
- 解析php中static,const与define的使用区别
- php中static、const和define的区别
- php中static、const和define的区别
- C++中const,define和static的区别
- C++中define、const和static的区别
- iOS基础之define,const,extern,static
- 正确使用#define,const,static,extern
- 【C++】用const修饰变量与define的区别
- iOS#define和static const
- iOS 关键字 static extern const volatile 区别及应用场景
- CSS3 pointer-events:none应用举例及扩展
- 初学NDK
- JAVA基础之选择排序
- effective c++以独立语句将newed对象植入智能指针
- ubuntu python 2.7 升级到 3.3
- iOS 中extern、static修饰变量的使用及define和const区别
- 杂谈:火星救援和未来城市
- android6.0 蓝牙搜索不到设备 BluetoothAdapter.getDefaultAdapter().startDiscovery()不起作用
- perl笔记--http://perldoc.perl.org/perlintro.html
- windows下导出文件夹的目录树
- boost 字符串处理(2)
- iOS_开发_工具_Terminal命令
- Libevent源码学习(三) 事件内部流程解析上部
- 颜色所代表的人的性格