您的位置:首页 > 移动开发 > IOS开发

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);

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 代码