item based NSBrowser

Gerriet M. Denkmann

Xcode tells me that:
'matrix(inColumn:)' was deprecated in macOS 10.10: Use the item based NSBrowser instead

And when I use parentForItemsInColumn it crashes with:
parentForItemsInColumn: is not supported for browsers with matrix delegates.

NSBrowser.h says:
" Note: the matrix based NSBrowser is deprecated in Mac OS 10.10. New code should use the item based interface.”

These seem to be the "matrix based NSBrowser” methods:
- (NSInteger)browser:(NSBrowser *)sender numberOfRowsInColumn:(NSInteger)column;
- (void)browser:(NSBrowser *)sender createRowsForColumn:(NSInteger)column inMatrix:(NSMatrix *)matrix;

"Alternatively, implement all of the following methods”
- (NSInteger)browser:(NSBrowser *)browser numberOfChildrenOfItem:(nullable id)item API_AVAILABLE(macos(10.6));
- (id)browser:(NSBrowser *)browser child:(NSInteger)index ofItem:(nullable id)item API_AVAILABLE(macos(10.6));
- (BOOL)browser:(NSBrowser *)browser isLeafItem:(nullable id)item API_AVAILABLE(macos(10.6));
- (nullable id)browser:(NSBrowser *)browser objectValueForItem:(nullable id)item API_AVAILABLE(macos(10.6));

So I tried:

func browser(_ browser: NSBrowser, numberOfChildrenOfItem item: Any?) -> Int { 5 }
func browser(_ browser: NSBrowser, child index: Int, ofItem item: Any?) -> Any { "test” }
func isLeafItem(_ item: Any?) -> Bool { false }
func browser(_ browser: NSBrowser, objectValueForItem item: Any?) -> Any? { item }

But when I run this, I get:

*** Illegal NSBrowser delegate (<TestBrowser.AppDelegate: 0x600003c19300>). Must implement browser:willDisplayCell:atRow:column: and either browser:numberOfRowsInColumn: or browser:createRowsForColumn:inMatrix:

and my browser is completely empty.

So: how do I create an "item based NSBrowser" with a delegate using "item data source methods” ?


Join to automatically receive all group messages.