美文网首页
用extern + const定义常量替换宏定义常量

用extern + const定义常量替换宏定义常量

作者: springerPrivate | 来源:发表于2017-05-09 17:09 被阅读0次

extern + const

//  Const.h

#import

extern NSString *const NOTIRY_NAME;

@interface Const : NSObject

@end

//  Const.m

#import "Const.h"

NSString *const NOTIRY_NAME = @"NOTIRY_NAME";

@implementation Const

@end

注:

extern声明也可以写在@interface 中,但是参考苹果的API没有这样做

宏定义常量

//  Macro.h

#ifndef Macro_h

#define Macro_h

#define NOTIRY_NAME @"NOTIRY_NAME"

#endif /* Macro_h */

相关文章

网友评论

      本文标题:用extern + const定义常量替换宏定义常量

      本文链接:https://www.haomeiwen.com/subject/pwhitxtx.html