ios - Module-Swift.h 有编译错误

标签 ios objective-c swift

我有一个在 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/

相关文章:

ios - 删除 UITableViewCell 选择

objective-c - WMV 转换器失败 FFMpeg

ios - 将每个 ChildViewController 上的数据传递到 UIPageViewController 上的下一个 ChildViewController

swift - 如果连接到快速查看 Controller ,选择器将不起作用

Swift - 如何显示一小时的一部分?

ios - 从自定义iOS应用程序启动设置应用程序

ios - super.viewDidLoad()前后不同的UIImageView.frame.size : what am I doing wrong?

ios - 如何使用自动布局堆叠 3 个 UI 元素

iphone - 解析json嵌套对象和数组的组合

ios - ios 中的应用程序委托(delegate)未调用方法