It seems that it's impossible to conform to the NSTextCheckingClient
protocol in Swift. The protocol requires that you implement:
func candidateListTouchBarItem() -> NSCandidateListTouchBarItem<AnyObject>?
But the compiler gives this error when you add that method:
Method 'candidateListTouchBarItem()' with Objective-C selector 'candidateListTouchBarItem' conflicts with getter for 'candidateListTouchBarItem' from superclass 'NSView' with the same Objective-C selector
The problem seems very similar to this other issue, so I expect there isn't a solution. Posting here so that others can find in search engine... or maybe someone knows a workaround?
Here's what I'm trying:
class MyTextView: NSView, NSTextCheckingClient {
func annotatedSubstring(forProposedRange range: NSRange, actualRange: NSRangePointer?) -> NSAttributedString? {
fatalError()
}
func setAnnotations(_ annotations: [NSAttributedString.Key : String], range: NSRange) {
fatalError()
}
func addAnnotations(_ annotations: [NSAttributedString.Key : String], range: NSRange) {
fatalError()
}
func removeAnnotation(_ annotationName: NSAttributedString.Key, range: NSRange) {
fatalError()
}
func replaceCharacters(in range: NSRange, withAnnotatedString annotatedString: NSAttributedString) {
fatalError()
}
func selectAndShow(_ range: NSRange) {
fatalError()
}
func view(for range: NSRange, firstRect: NSRectPointer?, actualRange: NSRangePointer?) -> NSView? {
fatalError()
}
func candidateListTouchBarItem() -> NSCandidateListTouchBarItem<AnyObject>? {
fatalError()
}
func insertText(_ string: Any, replacementRange: NSRange) {
fatalError()
}
func setMarkedText(_ string: Any, selectedRange: NSRange, replacementRange: NSRange) {
fatalError()
}
func unmarkText() {
fatalError()
}
func selectedRange() -> NSRange {
fatalError()
}
func markedRange() -> NSRange {
fatalError()
}
func hasMarkedText() -> Bool {
fatalError()
}
func attributedSubstring(forProposedRange range: NSRange, actualRange: NSRangePointer?) -> NSAttributedString? {
fatalError()
}
func validAttributesForMarkedText() -> [NSAttributedString.Key] {
fatalError()
}
func firstRect(forCharacterRange range: NSRange, actualRange: NSRangePointer?) -> NSRect {
fatalError()
}
func characterIndex(for point: NSPoint) -> Int {
fatalError()
}
}
I've reported this as: FB9954366