Thanks. The part I was missing is the one the documentation for NSTextContentManager
doesn't mention, which is that it is an abstract class whose (apparently) only concrete subclass is NSTextContentStorage
, which has a textStorage
property.
guard let textStorage: NSTextStorage = (textLayoutManager?.textContentManager as? NSTextContentStorage)?.textStorage else { return }
The sample code also changes the textStorage
inside the block passed to textContentManager.performEditingTransaction(_:)
, which the documentation doesn't seem to explain why it's necessary.