Re: item based NSBrowser


Gerriet M. Denkmann
 

On 4 Jan 2021, at 21:58, Bill Cheeseman <wjcheeseman@comcast.net> wrote:

Back when I was first starting to develop my UI Browser product, https://pfiddlesoft.com/uibrowser, there were three helpful Objective-C Cocoa code examples for NSBrowser from Apple: SimpleCocoaBrowser, ComplexBrowser, and AnimatedTableView. I haven't looked at them in a long time, but I'm sure you can find them somewhere.
I found the SimpleCocoaBrowser (thanks very much for your hint) and it works just fine.

The BrowserDelegate (called AppController in the sample code) implements 4 required + 1 optional methods:
- (id)rootItemForBrowser:(NSBrowser *)browser (optional)
- (NSInteger)browser:(NSBrowser *)browser numberOfChildrenOfItem:(id)item
- (id)browser:(NSBrowser *)browser child:(NSInteger)index ofItem:(id)item
- (BOOL)browser:(NSBrowser *)browser isLeafItem:(id)item
- (id)browser:(NSBrowser *)browser objectValueForItem:(id)item

Then I rewrote the BrowserDelegate in Swift, and again I got:

*** Illegal NSBrowser delegate (<SimpleBrowser.SwiftBrowserDelegate: 0x600001221260>). Must implement browser:willDisplayCell:atRow:column: and either browser:numberOfRowsInColumn: or browser:createRowsForColumn:inMatrix:

The reason:

I implemented:
func isLeafItem(_ item: Any?) -> Bool { false } ← wrong

instead of:
func browser(_ browser: NSBrowser, isLeafItem item: Any?) -> Bool { false }

A rather stupid mistake.
But the error message was not very helpful.

Thanks again for your help!

Gerriet.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.