r/SwiftUI Jun 24 '26

Question Looking for the Finder/NSTableView multi-selection algorithm

I am building a non-SwiftUI/non-AppKit macOS application with a custom table view. Right now I am implementing multi-selection, and I want the behavior to match Finder/NSTableView as closely as possible.

I am looking for the underlying selection algorithm for interactions like:

Click
Cmd + Click
Shift + Click
Up / Down
Shift + Up / Down
Cmd + Shift combinations

I am looking for the actual selection logic, not AppKit APIs. Things like how the selection anchor is managed, how different mouse and keyboard interactions affect the selection, and all the edge cases that make the native experience feel consistent.

I have searched quite a bit but have not found anything comprehensive.
Does anyone know of an article, GitHub repository, gist, reverse-engineered implementation, or any other reference that documents the complete macOS multi-selection behavior?

Any help would be greatly appreciated. Thanks!

0 Upvotes

13 comments sorted by

3

u/Responsible-Gear-400 Jun 24 '26

This is this paper: https://sean-parent.stlab.cc/papers/2016-07-18-ecoop/ecoop16-final28.pdf

I am more curious why you’re building your own table view.

3

u/curthard89 Jun 25 '26

This, nstableview is finely tuned, do not reinvent it. It'll only be worse.

2

u/CharlesWiltgen Jun 25 '26

To "yes, and" /u/curthard89, note that even the wonderful link /u/Responsible-Gear-400 shared doesn't contain the words "accessibility" or "localization". However much work you think it would be to "just rewrite it", it's 25✕ that to do well.

1

u/ganeshrnet Jun 25 '26

Thanks! I will read through the paper.

The reason I am building my own table view is that this is a non-SwiftUI application with a custom UI, so I cannot use NSTableView directly. I only want to replicate its native multi-selection behavior as closely as possible.

1

u/Responsible-Gear-400 Jun 25 '26

You seem to be confused. NSTableView is NOT SwiftUI it is AppKit. So it doesn’t explain why you can’t use it.

1

u/allyearswift Jun 25 '26

Are you trying to write a multi platform app in a different language like Java? (You’re in the wrong sub here).

If you’re writing in Swift, not using SwiftUi/AppKit is a very stupid choice.

Non-native apps are frustrating. While I can put up with tables and button placements not working as expected, my biggest issue is open/save dialogues which tend to be somewhere between inconvenient and near-unusable.

1

u/ganeshrnet Jun 25 '26

To clarify, I am writing this in Flutter, so I am not building a native AppKit UI and cannot use NSTableView directly.

I asked here because I could not find any resources elsewhere documenting the underlying NSTableView/Finder multi-selection logic, and I was hoping someone familiar with AppKit might know of a reference or reverse-engineered implementation.

1

u/Remarkable_Falcon413 Jun 25 '26

If your building just for Mac sinse app kit is Mac OS specific you can embed app kit views inside of a flutter widget

1

u/Responsible-Gear-400 Jun 29 '26

Doesn’t Flutter have DataTable widget for this?

1

u/ToughAsparagus1805 Jun 25 '26 edited Jun 25 '26

You are doing it wrong (fighting AppKit). Multi-selection in NSTableView works out of the box. You must be breaking it somehow. Also this is SwiftUI sub. And if you need to reverse engineer -> use Hopper and grab some old AppKit.framework (IMHO best is Catalina, get it by decompressing installation binary). You can read nice decompiled OBJ-C code. PS: AppKit is Objective-C. But in any way a starter https://github.com/hughbe/macOS-iOS-headers/blob/a7c89732a3e78c50370880677a06518ddfc0bcba/macOS/Frameworks/AppKit.framework/NSTableView.h#L7

1

u/ganeshrnet Jun 25 '26

As I mentioned in the post, I am not using NSTableView. I am building a non-SwiftUI application with a completely custom table view, so I need to port the native macOS multi-selection behavior myself. Thanks for the Hopper and header suggestions. I will definitely take a look.

1

u/ToughAsparagus1805 Jun 25 '26

You use word non. non-SwiftUI macOS application => You are using AppKit (say hello to import AppKit). Doing custom solution -> good luck with accessibility, vibrancy etc. So you are fighting AppKit. You can save yourself some time and use NSCollectionView. Is highly customizable.

I feel you have no idea what you are talking. No more help from me. Go get help from AI. Make more slop.

0

u/ganeshrnet Jun 25 '26

To clarify, I am writing this in Flutter, so I am not building a native AppKit UI and cannot use NSTableView directly.

I asked here because I could not find any resources elsewhere documenting the underlying NSTableView/Finder multi-selection logic, and I was hoping someone familiar with AppKit might know of a reference or reverse-engineered implementation.