Post

Replies

Boosts

Views

Activity

Issue with Landmarks Demo: macApp crashes
I'm new to Swift and SwiftUI, so I followed this tutorial - https://developer.apple.com/tutorials/swiftui. During and after the development I could find some issues like bugs and runtime warnings (even when building using the Apple's project files). Here's one of them (let me know if I can post all the issues here, or if I should create a question for each one). The major issue is in the macOS app. When there are no favorite landmarks, if you select in the filters "Favorites Only", nothing changes and the app crashes when you click on another landmark! What is surprising is that on iPhone and iPad this works perfectly! After one day of debugging I managed to reproduce the issue in a few lines of code: lang-swift import SwiftUI struct ContentView: View { @State private var filterAll = false let allDummyData: [String] = [ "A", "B", "C" ] var filteredDummyData: [String] { /* Simulates fully filtered data */ filterAll ? [String]() : allDummyData } var body: some View { NavigationView { List { ForEach(filteredDummyData, id: \.self) { dummy in NavigationLink(destination: Text(dummy)) { Text(dummy) } } } .toolbar { ToolbarItem { Menu { Toggle(isOn: $filterAll) { Text("Filter All") } } label: { Label("Filter", systemImage: "slider.horizontal.3") } } } Text("Placeholder") } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } The funny thing is that the error magically disappears if you remove .toolbar (and move the Toggle in List) or if you remove the Text("Placeholder")! I have no clue why this causes such a horrible issue. My questions are: Is it a bug or is it the expected behavior? How should I fix it keeping the wanted result? Should I report this to Apple in order to fix the tutorial? How should I do that?
1
0
394
Mar ’21