Can NSTextView work with custom NSTextContentManager implementation? (TextKit2)

I'm trying to implement custom NSTextContentManager and use it with NSTextView, however it seems that NSTextView expect NSTextContentStorage all the time.

final class MyTextContentManager: NSTextContentManager {
    // ...
}

It's added to layout manager, and NSTextView instance finds it properly:

let textContentManager = MyTextContentManager()        textContentManager.addTextLayoutManager(textLayoutManager)

however, when I use it, I see errors at:

[MyTextContentManager textStorage]: unrecognized selector sent to instance 0x600003d84870

the textStorage property is part of NSTextStorageObserving, that is not NSTextContentManager interface.

It looks like NSTextView is not ready to work with custom NSTextContentManager. What did I miss?

Answered by krzyzanowskim in 770583022

I don't think NSTextView / UITextView ever gets support for NSTextContentManager. That's one of the reasons I created STTextView, which is a custom TextKit 2 based text view implementation, you may want find useful in that regard.

I am trying to provide my own NSTextLocation subclass and I encounter a similar problem: an unrecognized selector range is sent to an NSTextRange instance that I create.

It seems like it may be necessary to subclass every class in the cluster NSTextContentManager <-> NSTextLayoutManager <-> NSTextLocation to produce something that works.

Can Apple provide any guidance?

Just stumbled across this as well. Still does not seem to have changed by macOS 14…

Accepted Answer

I don't think NSTextView / UITextView ever gets support for NSTextContentManager. That's one of the reasons I created STTextView, which is a custom TextKit 2 based text view implementation, you may want find useful in that regard.

Can NSTextView work with custom NSTextContentManager implementation? (TextKit2)
 
 
Q