Set the Sidebar Initial Width in SwiftUI Navigation Split View

When you use a navigation split view in a SwiftUI Mac app, you normally have a sidebar in the left column. You want to give the sidebar an initial width that is wide enough to show the sidebar contents while letting people resize the sidebar. How do you provide the initial width?

Add the .navigationSplitViewColumnWidth modifier to the sidebar view and supply the initial width you want. The following code sets the sidebar width to 192 points:

NavigationSplitView {
	Sidebar()
    	.navigationSplitViewColumnWidth(ideal: 192)
} detail: {
  	DetailView()
}

Get the Swift Dev Journal Newsletter

Subscribe and get exclusive articles, a free guide on moving from tutorials to making your first app, notices of sales on books, and anything I decide to add in the future.

    We won't send you spam. Unsubscribe at any time.