iOS:如何从 Swift 文件中的 Constant.h ObjC 获取 #define?
iOS: How to get the #define from a Constant.h ObjC in a Swift File?
当我在 constant.h 文件中写入时:
#define WS_PLANNING_INFORMATION "registrations/"
当我从 Swift 文件中调用它时它起作用了。
但是如果我在 constant.h 文件中写这个:
#define WS_PLANNING_INFORMATION "registrations/" CRYPTOKEY
没用。 swift 文件不再显示 WS_PLANNING_INFORMATION。
有没有简单的方法连接 constant.h 文件中的两个字符串以便 swift 文件可以很好地检索?
(这个问题的有效答案非常有用,比那个更简单,不适合我)
使用常量代替宏。
在constant.h
extern const char *WS_PLANNING_INFORMATION;
在constant.m
const char *WS_PLANNING_INFORMATION = "registrations/" CRYPTOKEY;
如果您打算使用 NSString *
而不是 char *
在constant.h
extern const NSString *WS_PLANNING_INFORMATION;
在constant.m
const NSString *WS_PLANNING_INFORMATION = @"registrations/" CRYPTOKEY;
当我在 constant.h 文件中写入时:
#define WS_PLANNING_INFORMATION "registrations/"
当我从 Swift 文件中调用它时它起作用了。
但是如果我在 constant.h 文件中写这个:
#define WS_PLANNING_INFORMATION "registrations/" CRYPTOKEY
没用。 swift 文件不再显示 WS_PLANNING_INFORMATION。
有没有简单的方法连接 constant.h 文件中的两个字符串以便 swift 文件可以很好地检索?
(这个问题的有效答案非常有用,比那个
使用常量代替宏。
在constant.h
extern const char *WS_PLANNING_INFORMATION;
在constant.m
const char *WS_PLANNING_INFORMATION = "registrations/" CRYPTOKEY;
如果您打算使用 NSString *
而不是 char *
在constant.h
extern const NSString *WS_PLANNING_INFORMATION;
在constant.m
const NSString *WS_PLANNING_INFORMATION = @"registrations/" CRYPTOKEY;