有没有更好的方法来排除 tvOS 的 navigationBarTitle?

is there a better way to exclude navigationBarTitle for tvOS?

...重用具有 navigationBarTitle 的视图?还是我真的必须重复所有内容...只是没有 tvos 的 navigationBarTitle?

 #if os(iOS)

    NavigationLink(destination: CountryDetails(countryInfo: self.$userData.countryInfos[countryInfosIndex(of: country.name)])
                                .environmentObject(self.userData)
                                .navigationBarTitle(Text(country.name), displayMode: .inline) // <<<<<<<< the only difference
                        ) {
                            EmptyView() 
                        }.frame(width: 1, height: 1) 
 #else
    NavigationLink(destination: CountryDetails(countryInfo: self.$userData.countryInfos[countryInfosIndex(of: country.name)])
                                .environmentObject(self.userData)
                        ) {
                            // CountryRow(country: country)
                            EmptyView() 
                        }.frame(width: 1, height: 1) 
 #endif

试试这个方法

extension View {
    public func iosnavigationBarTitle(_ title: Text, 
             displayMode: NavigationBarItem.TitleDisplayMode = .inline) -> some View {
#if os(iOS)
        return self.navigationBarTitle(title, displayMode: displayMode)
#else
        return self
#endif
    }
}