I have this code inside which I'm calling "makeView" function that returns a View, and in the makeView function I'm incrementing the variable "id" and passing it to the View, but when I do this it shows this error
"Updating a preview from SongsList_Previews in SongBook.app (2935) took more than 5 seconds."
And surprisingly when I comment out the line "self.id += 1" everything works. I'm new to SwiftUI, so forgive me if I left out some information.
struct SongsList: View {
@State private var id: Int = 0
var body: some View {
VStack{
NavigationView {
List(songs) {
song in NavigationLink(
destination: SongMainView(song: song)) {
makeView(song: song)
}
}
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .leading)
.background(Color.orange.opacity(0.2))
.edgesIgnoringSafeArea(.all)
}
func makeView(song: Song) -> SongsIndexView {
self.id += 1;
return SongsIndexView(song: song, id: self.id)
}
}