Post

Replies

Boosts

Views

Activity

Failed to produce diagnostic for expression when creating a list view in SwiftUI
Hello! I am new to SwiftUI. Recently I am trying to create a list view for my app. However, when I add the list view using ForEach, an error will show up saying "Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project". When I comment out the ForEach, everything back to normal. I have no idea what is wrong to the code. Hope someone can help me out! Thank you! The code throw error: Swift struct PlaylistDetailView: View { var playlist: Playlist var body: some View { NavigationView{ VStack{ if playlist.songs.count == 0 { Text("No Songs") } else{ Text("Have Songs") List{ ForEach(playlist.songs){ item in SongRow(song: item) } } } } .navigationTitle(playlist.name) .navigationBarTitleDisplayMode(.inline) .toolbar(content: { ToolbarItem(placement: .navigationBarLeading) { Button(action: {}, label: { Text("Edit") }) } ToolbarItem(placement: .navigationBarTrailing) { Button(action: {}, label: { Image(systemName: "plus") }) } }) } } } The error shows on line 2. If I comment out line 12-15, everything back to normal. The definition of Playlist and Song is Swift struct Playlist: Codable, Identifiable { var id = UUID() var name: String var songs: [Song] } struct Song: Codable { var Name: String var URLs: URL }
2
0
679
May ’21