NavigationLink init(_:destination:) 已弃用

NavigationLink init(_:destination:) deprecated

NavigationLink 的初始化器

init<S>(_ title: S, destination: Destination) where S : StringProtocol

已弃用,仅适用于 iOS 13.0–15.2。替换为

init<S>(_ title: S, destination: () -> Destination) where S : StringProtocol

根据文档:https://developer.apple.com/documentation/swiftui/navigationlink/init(_:destination:)-6hslu

替换我现有的代码
NavigationLink("MyTitle") {
    Text("MyView")
}

显示错误

Type '() -> Text' cannot conform to 'View'

我使用推荐的初始化程序有什么问题?

编辑 1: Xcode 版本 12.5.1 (12E507)

从 Xcode 12.5.1 (12E507) 更新到 13.2.1 (13C100) 修复了这个问题。

Xcode12 中的 SwiftUI 源代码不包含将目标参数作为闭包类型的 NavigationLink 初始值设定项; Xcode 13 个做到了。