Sadly, I'm not sure that this is actually possible to do in pure Swift, given the definitions laid out in Obj-C.
When I start writing accessibilityRows()
, I see two possible overloads to implement:
-
accessibilityRows() -> [NSAccessibilityRow]?
comes from theNSAccessibilityTable
protocol, which is inherited fromNSAccessibilityOutline
and is a requirement to fulfill the protocol -
accessibilityRows() -> [Any]?
comes fromNSAccessibilityProtocol
, whichNSView
adopts (and which you would need tooverride
)
Because you inherit from both protocols, you'd need to override both methods to conform, but you can't because Swift is a bit more strict about Obj-C's rules than it is.
It also doesn't appear at first glance to be possible to get around using @_implements
:
class MyView: NSView, NSAccessibilityOutline { // error: type 'MyView' does not conform to protocol 'NSAccessibilityTable'
@_implements(NSAccessibilityTable, accessibilityRows)
func myAccessibilityRows() -> [NSAccessibilityRow]? {
nil
}
@objc
override func accessibilityRows() -> [Any]? { // note: candidate has non-matching type '() -> [Any]?'
nil
}
}
Someone might be able to come up with another creative solution, but this is likely at least worth filing a Radar for.
In the meantime, it may be sufficient for your use-case to write an Objective-C base class which handles the NSAccessibilityOutline
protocol implementation, with a concrete Swift subclass with the more "interesting" bits.