What is NSTextView "compatibility" mode in MacOS 10.12+

I have a app I have developed over last 17 years and I noticed an NSTextView field that I set up without word wrapping no longer scrolled in the horizontal direction. I turned off wrapping with a method from Apple documention (last updated 2019) with key code being

[[theTextView enclosingScrollView] setHasHorizontalScroller:YES];
[theTextView setHorizontallyResizable:YES];
[theTextView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[[theTextView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[theTextView textContainer] setWidthTracksTextView:NO];

It adds horizontal scroll bars, makes text view resizable in horizontal direction, makes the text container very wide, and sets container to track text view width changes.

But in MacOS 10.12 (or newer, I was using 10.13), the text view no longer resizes horizontally and one cannot scroll long lines in the horizontal direction. After 3-4 hours of trying various thinks, I found this tidbit in NSTextView documentsion

In macOS 12 and later, if you explicitly call the layoutManager property on a text view or text container, the framework reverts to a compatibility mode that uses NSLayoutManager.

I was then able to restore word wrapping with scrolling by adding the line

NSLayoutManager *lm = [theTextView layoutManager]

This call was enough; no need to use the layout manager. My code now works again.

My problem is solved, but the solution raises the questions --- what is "incompatibility" mode if this line is not called? Do I have to find all my NSTextViews and insert this call otherwise things won't work in MacOS 10.12+? And finally, what are the benefits of using "incompatibility" mode, which seems to stop using NSLayoutManager, and how does one do layout in that mode? The brief developer documentation in XCode did not make that clear.

Apple rewrote the whole layout and text framework used by Cocoa views. The rewrite was incremental, so some features were not yet available on some previous macOS versions, and some behaviours may differ. Anyway, setting a layout manager makes it use the old layout and text framework, so you will have the same behaviour as in older macOS versions. You can either try to find a way to get the wanted behaviour with the new framework, or keep using the old one for now I guess. I think there is some info on the AppKit release notes and in various WWDC sessions.

and in various WWDC sessions.

Yep. Specifically:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What is NSTextView "compatibility" mode in MacOS 10.12+
 
 
Q