Having a warning while using NavigationLink inside my Hstack

Hi, I have recently started learning Swift and was wondering if there is any fix/solution to the warnings that I get. Currently running on Xcode Version 14.3.1. With emulator Iphone 14 pro - IOS 16.4, Swift ver 5.8.1.

'init(destination:tag:selection:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView

This forum is more about the Swift language itself, not SwiftUI (which is an Apple framework that's independent of the language.)

However, in general SwiftUI prefers these to be done via the .navigationDestination modifier.

HStack(spacing: 0) {
    NavigationLink(value: appMode) {
        // Contents
    }
}
.navigationDestination(for: AppMode.self) {
    switch appMode {
    case .ground:
        GroundView()
    case .air:
        AirView()
    case .logs:
        LogsView()
    }
}

Writing it this way means you don't need to duplicate the view for each possible AppMode value.

2 Likes