2

I was using Xcode 10.1 and used SWIFT_VERSION 3.0 in Objective-C project. The below code worked fine with Swift 3.

RichTextEditor.swift:

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

Objective-C class calls above method:

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

Above Objective-C code was working with Swift 3 and once I changed it to SWIFT_VERSION 4, the below error occurred.

enter image description here

How can I fix this issue? I was googling this but I could not find a solution.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Wanker Silva
  • 413
  • 4
  • 18

1 Answers1

8

You need to add @objc in method declaration to get access of it in objective c. like this,

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)
    }
}
Dhaval Bhimani
  • 980
  • 1
  • 13
  • 24