0

I'm getting Xcode compiler error when trying to subclass UIContextMenuConfiguration.

Here's simple code that reproduces the problem:

@available(iOS 13.0, *)
class DateDifferenceContextMenu: UIContextMenuConfiguration {
    init(indexPath: IndexPath, dateDifference: Int) {
        super.init(identifier: nil, previewProvider: nil, actionProvider: nil)
    }
}

The error reads:

Must call a designated initializer of the superclass 'UIContextMenuConfiguration'.

My super call matches the designated initializer. What's wrong?

Gereon
  • 17,258
  • 4
  • 42
  • 73
Phantom59
  • 947
  • 1
  • 8
  • 19

1 Answers1

2

My super call matches the designated initializer.

No, it calls a convenience initializer.

Change your code to either simply call super.init(), or make your initializer be a convenience well. I.e.:

class DateDifferenceContextMenu: UIContextMenuConfiguration {
    // use either this
    convenience init(indexPath: IndexPath, dateDifference: Int) {
        self.init(identifier: nil, previewProvider: nil, actionProvider: nil)
    }

    // or this
    init(indexPath: IndexPath, dateDifference: Int) {
        super.init()
    }

}
Gereon
  • 17,258
  • 4
  • 42
  • 73
  • Thanks! You're so right! I looked at the class definition and missed that it only has a convenience init(). The true init() is from NSObject. – Phantom59 Sep 13 '20 at 16:05