I need to know when TextKit
's NSTextContainer
's size
changes, so I can update some caches in my NSLayoutManager
. How can I receive notifications when size
changes? Does TextKit
in general (and NSTextContainer
's size
property specifically) support KVO? I reviewed the NSTextContainer.h
header and the NSTextContainer
documetation, and I can't find anything about it either way.

- 30,998
- 16
- 147
- 256
1 Answers
NSTextContainer
is supposed to call -[NSLayoutManager textContainerChangedGeometry:]
on its NSLayoutManager
when its size or shape changes:
This method is invoked automatically by other components of the text system; you should rarely need to invoke it directly. Subclasses of NSTextContainer, however, must invoke this method any time their size of shape changes (a text container that dynamically adjusts its shape to wrap text around placed graphics, for example, must do so when a graphic is added, moved, or removed).
I haven't tested this to determine if it requires that heightTracksTextView
or widthTracksTextView
be set on the NSTextContainer
; that verticallyResizable
or horizontallyResizable
be set on the NSLayoutManager
; or that programmatically calling -[NSTextContainer setSize:]
or -[NSTextContainer setSimpleRectangularTextContainer:]
will automatically call -[NSLayoutManager textContainerChangedGeometry:]
as advertised.

- 30,998
- 16
- 147
- 256