iOS定义字符串常量

1,978 阅读1分钟

定义字符串常量

 我们需要使用一些私有的常量,正常在.m文件中声明,也可以在.h中定义全局常量。

 /// 显示远程推送内容
static NSString * const ShowRemoteNotificationContentKey = @"ShowRemoteNotificationContentKey";

/// 刷新裸车毛利数据
static NSString * const RefreshDealerGrossProfitNotificationKey = @"RefreshDealerGrossProfitNotificationKey";

/// 需要重新登录
static NSString * const ReLoginNotificationKey = @"ReLoginNotificationKey";

/// 刷新竞品价格数据
static NSString * const RefreshCompetitivePricesNotificationKey = @"RefreshCompetitivePricesNotificationKey";

 正常公开的字符串常量定义方式是使用extern关键字,不建议使用#define。

 在.h文件中定义

 /// 用户Token Key
extern NSString * const QXUserTokenKey;

/// 用户UUID
extern NSString * const QXUserUUIDKey;

/// 用户所在的城市
extern NSString * const QXUserCityKey;

/// 第一次启动应用
extern NSString * const QXFirstLaunchKey; 

 在.m文件中

/// 用户Token Key
NSString * const QXUserTokenKey = @"com.qianxx.user.token";

/// 用户UUID
NSString * const QXUserUUIDKey = @"com.qianxx.user.uuid";

/// 用户所在的城市
NSString * const QXUserCityKey = @"com.qianxx.user.city";

/// 第一次启动应用
NSString * const QXFirstLaunchKey = @"com.qianxx.user.isFirstLaunch";