我有一个在 Objective-C 中使用的 swift 类,所以 Module-Swift.h 是自动生成的。但是,自动生成的 .h 文件有编译错误...代码如下所示:
class SwiftClass: ObjectiveCClass {
let enteringStr : String = "Entering"
let exitingStr :String = "Exiting"
let dwellInsideStr : String = "Dwell Inside"
let dwellOutsideStr :String = "Dwell Outside"
var userId : String?
var triggerType : String?
在生成的 Module-Swift.h 文件中,它看起来是这样的:
SWIFT_CLASS("SwiftClass")
@interface SwiftClass : ObjectiveCClass
@property (nonatomic, readonly, copy) NSString * enteringStr;
@property (nonatomic, readonly, copy) NSString * exitingStr;
@property (nonatomic, readonly, copy) NSString * dwellInsideStr;
@property (nonatomic, readonly, copy) NSString * dwellOutsideStr;
@property (nonatomic, copy) NSString * userId;
@property (nonatomic, copy) NSString * triggerType;
但是,前4个变量有很多编译错误。它们是:
- 预期';'在声明列表的末尾
- 在“@”之后需要一个 Objective-C 指令
- 预期成员名称为“;”声明说明符之后
- 属性需要命名字段
所有 4 个错误都相同。 ObjectiveCClass 是扩展 NSOBject 的第三方 API 类。更奇怪的是,我在项目中只是将几个objective-c类改成swift的时候并没有出现这个错误,而且这个类之前已经迁移成功了。但是,这是在我更多地迁移到 swift 之后出现的。
最佳答案
您的 objective-c 代码中的其他地方可能有同名的属性
关于ios - Module-Swift.h 有编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25448156/