【问题标题】:iOS: How to get the #define from a Constant.h ObjC in a Swift File? [duplicate]iOS:如何从 Swift 文件中的 Constant.h ObjC 获取#define? [复制]
【发布时间】:2018-07-27 09:47:14
【问题描述】:

当我将这个写在 constant.h 文件中时:

#define WS_PLANNING_INFORMATION "registrations/"

当我从 Swift 文件中调用它时它可以工作。

但是如果我把这个写在 constant.h 文件中:

#define WS_PLANNING_INFORMATION "registrations/" CRYPTOKEY

它不起作用。 swift 文件不再看到 WS_PLANNING_INFORMATION。

有没有一种简单的方法可以连接 constant.h 文件中的两个字符串,以便 swift 文件很好地检索?

(这个问题的验证答案非常有用,比ticket 更简单,这不适合我)

【问题讨论】:

  • 不。首先,您不应该将宏用于字符串常量。

标签: ios objective-c swift constants string-concatenation


【解决方案1】:

使用常量而不是宏。

在常量.h中

extern const char *WS_PLANNING_INFORMATION;

在常量.m中

const char *WS_PLANNING_INFORMATION = "registrations/" CRYPTOKEY;

如果您的意思是使用NSString * 而不是char *

在常量.h中

extern const NSString *WS_PLANNING_INFORMATION;

在常量.m中

const NSString *WS_PLANNING_INFORMATION = @"registrations/" CRYPTOKEY;

【讨论】:

  • 我一直在寻找那个。非常感谢:D
猜你喜欢
  • 1970-01-01
  • 2018-03-03
  • 2021-12-23
  • 2017-05-05
  • 2013-05-14
  • 1970-01-01
  • 2013-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多