Whats the Appkit equivalent of SwiftUI's NavigationSplitView?

How do I implement the same Navigation split view with a side bar in Appkit?

Basically I have this code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationSplitView {
            // Sidebar
            List {
                NavigationLink("Item 1", value: "Item 1 Details")
                NavigationLink("Item 2", value: "Item 2 Details")
                NavigationLink("Item 3", value: "Item 3 Details")
            }
            .navigationTitle("Items")
        } content: {
            // Main content (detail view for selected item)
            Text("Select an item to see details.")
                .padding()
        } detail: {
            // Detail view (for the selected item)
            Text("Select an item from the sidebar to view details.")
                .padding()
        }
    }
}


struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

and wanted to somehow convert it to Appkit. I tried to use an NSSplitViewController but I still don't have that side bar and that button to collapse it, how do I go about this?

The sidebar is the result of using the Source List style for your navigation table view.

You have to add the sidebar toggle button yourself. Set the "isNavigational" property to true so that it appears in a navigation location in the titlebar.

I think there is some sort of "toggleSidebar" operation. There is a menu item for it. But the built-in operation isn't animated. For an animated collapse, you'll need to set the "isCollapsed" property of first NSSplitViewItem, using the "animator()" proxy, of course.

Rest assured, it is much more complicated than it sounds. There's a reason why SwiftUI is so popular. If you hit the wall on what SwiftUI offers, you have to make some hard choices.

I don't think it's hard to do this in AppKit. It's just different.

I haven't done this in awhile. But I'm pretty sure you could use NSSplitViewController.

@interface NSSplitViewController (NSSplitViewControllerToggleSidebarAction)

/// Animatedly collapses or uncollapses the first sidebar split view item in the receiver. Does nothing if the receiver does not contain any sidebars.
- (IBAction)toggleSidebar:(nullable id)sender API_AVAILABLE(macos(10.11));

/// Animatedly collapses or uncollapses the first inspector split view item in the receiver. Does nothing if the receiver does not contain any inspectors.
- (IBAction)toggleInspector:(nullable id)sender API_AVAILABLE(macos(14.0));

@end

To get the toggle sidebar button in the toolbar you need to build an NSToolbar on your window. You could do this in Interface Builder or programmatically. Add a toolbar item to the toolbar with the following identifier:

// A standard item that is configured to send -toggleSidebar: to the firstResponder when invoked. 
APPKIT_EXTERN NSToolbarItemIdentifier NSToolbarToggleSidebarItemIdentifier 

You might find this sample code helpful. https://developer.apple.com/documentation/appkit/integrating-a-toolbar-and-touch-bar-into-your-app?language=objc

Whats the Appkit equivalent of SwiftUI's NavigationSplitView?
 
 
Q