OutlineGroup с навигационной ссылкой
Я попытался добавить метку для NavigationLink в OutlineGroup с замыканием, но это не сработало. Я получаю эту ошибку: компилятор не может проверить тип этого выражения за разумное время; попробуйте разбить выражение на отдельные подвыражения
Этот код работает:
struct ContentView: View {
@State var showPreferencesView = false
@State var showAboutView = false
@ObservedObject var preferences = Preferences()
var body: some View {
VStack (alignment: .center) {
Text("The Book")
.font (.subheadline)
.fontWeight(.semibold)
.foregroundColor(Color.red)
}
NavigationView {
List (tocEntries, children: \.children) { entry in
if (entry.section == "Introduction" || entry.section == "The Hours" || entry.section == "The Occasions") {
Text(entry.section)
.font(.headline)
} else {
NavigationLink ("\(entry.tocEntryData!.hourName)", destination: HourView (hourItem: entry.tocEntryData!, preferences: preferences))
}
}
.navigationBarTitle("The Book", displayMode: .automatic)
.navigationBarItems(
leading: Button(action: {self.showAboutView.toggle()}) {Text ("About").bold()
.sheet(isPresented: $showAboutView) {AboutView(showAboutView: self.$showAboutView, preferences: preferences)}
},
trailing: Button (action: {self.showPreferencesView.toggle()}){Image(systemName: "gear").imageScale(.large)})
.sheet(isPresented: $showPreferencesView) {PreferencesView(showPreferencesView: self.$showPreferencesView, preferences: preferences)}
.preferredColorScheme(preferences.preferredColor)
}
}
}
Но когда я меняю
NavigationLink ("\(entry.tocEntryData!.hourName)", destination: HourView (hourItem: entry.tocEntryData!, preferences: preferences))
к:
NavigationLink (destination: HourView (hourItem: entry.tocEntryData!, preferences: preferences)) {
HStack {
Text ("\(entry.tocEntryData!.hourName)")
}
}
Я получаю ошибку. Любая помощь приветствуется! Спасибо!