iOS 全局常量const
2016-08-01 17:55
323 查看
新建一个类 UBConst.h
.h
@interface UBConst :
NSObject
extern NSString *const HTTP_URL;
extern const
int DEFAULT_PORT;
@end
.m
#import "UBConst.h"
@implementation UBConst
const int DEFAULT_PORT =
80;
NSString *
const HTTP_URL =
@"http://www.kjson.com/jsonparser/";
@end
3.ViewController.h中使用
#import "ViewController.h"
#import "UBConst.h"
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
self.view.backgroundColor = [UIColor
whiteColor];
NSString *string = [NSString
stringWithFormat:@"我是%@",HTTP_URL];
NSLog(@"222222====%@ and ==== %d",string,DEFAULT_PORT);
}
.h
@interface UBConst :
NSObject
extern NSString *const HTTP_URL;
extern const
int DEFAULT_PORT;
@end
.m
#import "UBConst.h"
@implementation UBConst
const int DEFAULT_PORT =
80;
NSString *
const HTTP_URL =
@"http://www.kjson.com/jsonparser/";
@end
3.ViewController.h中使用
#import "ViewController.h"
#import "UBConst.h"
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
self.view.backgroundColor = [UIColor
whiteColor];
NSString *string = [NSString
stringWithFormat:@"我是%@",HTTP_URL];
NSLog(@"222222====%@ and ==== %d",string,DEFAULT_PORT);
}
相关文章推荐
- android 代码实现控件之间的间距
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- [Android]在代码里运行另一个程序的方法
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- 肯特·贝克:改变人生的代码整理魔法
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 网页恶意代码的预防
- 高手写的Tracer-Flash代码调试类代码下载
- CSS代码缩写技巧
- 非主流Q-zOne代码代码搜集第1/2页
- CreateWeb.vbs 代码
- Lua中编译执行代码相关的函数详解
- 更有效率的css代码编写第1/3页
- 代码中到底应不应当写注释?
- SQL语言查询基础:连接查询 联合查询 代码
- 论坛头像随机变换代码