尝试使用 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/