objective-c - #Swift 中的定义和变量

标签 objective-c variables swift

尝试使用 Swift 无法识别的#define。问题很容易得到解答,我将其保留在这里以供将来引用,以防万一有人需要它

//PrefsString.h    

#define PREFS [FISettings sharedSettings]


@interface FISettings : MYSSharedSettings
@property (nonatomic, weak) NSString *authToken;

创建变量:authToken

我用它来存储数据以便用户可以登录:

//SomeOtherView.m

PREFS.authToken = user.storeInfoString;

最佳答案

根据 swift 编程 guide

“In Swift, you can use functions and generics to achieve the same results [as complex macros] without any compromises. Therefore, the complex macros that are in C and Objective-C source files are not made available to your Swift code.”

所以你不能在 swift 代码中使用宏。你应该将其作为实用函数并在 swift 代码中使用。

关于objective-c - #Swift 中的定义和变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26133296/

相关文章:

ios - 从我的网络服务缓存图像 url 的最佳方式?

ios - 在 iOS 中解析 excel 文件

css - 我可以在 SASS mixin 中声明一个新变量吗?

ios - 修复 UIStackView 中元素的宽度

swift - 程序崩溃并在调试器中显示以下内容和 "lldb"- Swift 4

iphone - UITableView 单元格最初正确加载,但随后发生变化

php - 将多个变量传递给url中的另一个页面

jquery - 您可以从 img src 请求/获取变量吗?

ios - 当键盘出现时移动可变高度的 TextView

iphone - UITableView 不滚动到单元格