【问题标题】:Module-Swift.h has compile errorModule-Swift.h 有编译错误
【发布时间】:2014-08-22 13:25:30
【问题描述】:

我有一个在 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 之后出现的。

【问题讨论】:

  • 请添加ObjectiveCClass 代码和其他所有内容以使问题可重现。

标签: ios objective-c swift


【解决方案1】:

您的 Objective-c 代码中的其他地方可能有同名的属性

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多