IOS:定义常量
来源:互联网 发布:115网盘mac客户端 编辑:程序博客网 时间:2024/05/29 07:43
新建一个Constants.h文件:
//// Constants.h// HelloWorld////声明常量//export global constantsFOUNDATION_EXPORT NSString *const KEY_USER_NAME;FOUNDATION_EXPORT const int RETRY_COUNT;
新建Constants.m
//export global constantsNSString *const KEY_USER_NAME = @"user_name";const int RETRY_COUNT = 3;
HelloWorld-Prefix.pch文件中增加:
//// Prefix header for all source files of the 'HelloWorld' target in the 'HelloWorld' project//#import <Availability.h>#ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later."#endif#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import "Constants.h" //增加改行,引入全局常量#endif
引用常量的地方直接使用常量即可:
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. NSLog(@"key is %@,count is %d",KEY_USER_NAME,RETRY_COUNT);}
2013-06-30 22:48:06.633 HelloWorld[1665:c07] key is user_name,count is 3
- IOS:定义常量
- iOS定义字符串常量
- 关于iOS一些常量定义的技巧
- iOS 常量和全局变量的定义
- iOS定义常量的最佳实践
- iOS 不要用宏来定义你的常量
- iOS 不要用宏来定义你的常量
- iOS定义静态变量、静态常量、全局变量
- iOS 定义静态常量和宏定义的写法
- 常量定义
- 常量定义
- 定义常量
- 定义常量
- 常量定义
- iOS定义常量除了用宏还可以用FOUNDATION_EXPORT
- iOS 中的宏定义,常量,与枚举类型使用
- 阿里weex研究iOS(四)定义全局常量
- iOS中关于宏定义与常量的使用
- java、jsp、html命名规范和定义
- java连mssqlserver2k
- 庞果网reverse函数的题目
- 在 Cordova/Phonegap for Android 中包含中文文件名的页面
- ZOJ3720 Magnet Darts
- IOS:定义常量
- 【R高级教程】专题一:表达谱芯片的聚类分析
- Android升级ADT22后会报ClassNotFoundException的原因分析
- 利用Cursor+CursorAdapter实现界面实时更新
- 死水一样
- Windows Azure、Hyper-V全面支持Oracle数据库
- IE下实现placeholder效果,支持文本框和密码框
- 树的子结构
- linux驱动学习--第二十五天:第十三章:Linux 块设备驱动(二):gendisk(通用磁盘) 结构体