0

我在 Objective-C 项目中使用 Xcode 10.1 并使用 SWIFT_VERSION 3.0。下面的代码在 Swift 3 上运行良好。

RichTextEditor.swift:

init(frame: CGRect, editAccess: Int) {
    super.init(frame:frame)
}

Objective-C 类调用上述方法:

self.rchTextControl = [[RichTextEditor alloc] initWithFrame:CGRectMake(2, cellRowHeight, tableView.tableView.bounds.size.width-4, cellMessageHeight-cellRowHeight) editAccess:[sectionCtrlEditAccessValue intValue]];

上面的 Objective-C 代码正在使用 Swift 3,一旦我将其更改为 SWIFT_VERSION 4,就会发生以下错误。

在此处输入图像描述

我该如何解决这个问题?我在谷歌上搜索,但我找不到解决方案。

4

1 回答 1

2

您需要添加@objc方法声明才能在目标 c 中访问它。像这样,

class RichTextEditor : UIView {

override init(frame: CGRect) {
    super.init(frame: frame)
}
@objc init(frame: CGRect, editAccess: Int) {
    super.init(frame:frame)
}
required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}
}
于 2019-04-09T05:05:25.760 回答