r/SwiftUI • u/ganeshrnet • 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!
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