For iOS 16 and macOS 13 you can use a new Navigation API. I will show you example for Navigation Split View which implements a multicolumn navigation style in this SwiftUI tutorial. This works also on the iPhone when you set it up with List selections, but really shines for the mac and the iPad.
NavigationSplitView allows for further custom styling with navigationSplitViewStyle for prominentDetail and balanced. You can also set the column width and show/hide columns programmatically.
NavigationSplitView came with SwiftUI 4 during WWDC 2022.
00:00 introduction
04:48 NavigationSplitView with double column
10:28 SidebarView
20:52 Navigation updates with List selection
26:30 programmatic navigation
36:38 State restoration
43:43 NavigationSplitView for mac
45:54 NavigationSplitView with three columns
1:09:57 Settings view for macOS
1:14:15 State restoration
1:25:12 ColumnVisibility, show all columns programmatically
1:36:35 navigation split view style and column width
1:43:30 Summary
Useful resources:
WWDC 2022 The SwiftUI cookbook for navigation
https://developer.apple.com/videos/play/wwdc2022/10054/
Example Project https://developer.apple.com/documentation/swiftui/bringing_robust_navigation_structure_to_your_swiftui_app
IIf you liked what you learned and you want to see more, check out one of my courses!
👨💻 my SwiftUI course https://school.swiftyplace.com/courses/swiftui-course
👨💻 my Core Data and SwiftUI course https://school.swiftyplace.com/courses/swiftui-and-core-data
👩🏻💻 Combine course
https://school.swiftyplace.com/courses/master-combine-framework
⬇️ Project files: https://github.com/gahntpo/DoubleColumnNavigationSplitProject
https://github.com/gahntpo/TripleColumnNavigationSplitProject
StackNavigation view tutorial
https://youtu.be/piAiy5vlC9k
https://github.com/gahntpo/NavigationStackProject
#SwiftUI #Navigation #macos