NavigationLink's initializer
init<S>(_ title: S, destination: Destination) where S : StringProtocol
is deprecated and only available for iOS 13.0–15.2. The replacement is
init<S>(_ title: S, destination: () -> Destination) where S : StringProtocol
per the documentation: https://developer.apple.com/documentation/swiftui/navigationlink/init(_:destination:)-6hslu.
Replacing my existing code with
NavigationLink("MyTitle") {
Text("MyView")
}
shows the error
Type '() -> Text' cannot conform to 'View'
1. Only concrete types such as structs, enums and classes can conform to protocols
2. Required by generic struct 'NavigationLink' where 'Destination' = '() -> Text'
What's wrong with my use of the recommended initializer?
Using Xcode Version 12.5.1 (12E507). Here is the full view for reference:
import SwiftUI
struct Test: View {
var body: some View {
NavigationView {
NavigationLink("MyTitle") {
Text("MyView")
}
}
}
}
Selecting any option will automatically load the page