What is the standard process of subclassing NSTextLocation?

Cannot find any guidance in the forums and Developer Doc, the WWDC session Meet TextKit2 says this protocol is served for any location type espacially useful when the underlying doc model is not linear. But when I try to subclass the NSTextLocation with my own type to define a more structured location rather than a linear one, also with my own NSTextContentManager subclass implementation, I keep receiving the system internal Location model like NSCountableTextLocation compare to my location which cause the app to crash.

-[NSCountableTextLocation compare:] receiving unmatching type <MarkdownTK2.ChildIndexPathLocation: 0x9b2402aa0>

In my own NSTextContentManager subclass:

public override func offset(
from: any NSTextLocation,
to: any NSTextLocation
) -> Int {

this method will also both receive my own location and some times receiving the system defined location that I can not calculate the offset then just return zero.

The doc only says

If you provide your own implementation of the NSTextLocation protocol to manage locations in your content, subclass NSTextContentManager and implement your own storage object to support those locations.

  • OS
    • Development environment: Xcode 26.0, macOS 26.0
    • Run-time configuration: macOS 26.0
What is the standard process of subclassing NSTextLocation?
 
 
Q