Post

Replies

Boosts

Views

Activity

Reply to Swift data issue in queries in iOS 18, no pb in iOS 17
Finally, I found where the issue was : Section(header: Text("Without Genre")) { ForEach (songs){song in if let songGenres = song.genres { // <-- PB is here ! if songGenres.isEmpty{ NavigationLink { SongView(song: song) } label: { Text(song.text) } } } } .onDelete { indexSet in indexSet.forEach { index in let song = songs[index] modelContext.delete(song) } } } Then I decided to bypass by calling a function to get the song's genre. Section(header: Text("Without Genre")) { ForEach (songs){song in let songGenres = getGenres(song) { // Change has been made if songGenres.isEmpty{ NavigationLink { SongView(song: song) } label: { Text(song.text) } } } } .onDelete { indexSet in indexSet.forEach { index in let song = songs[index] modelContext.delete(song) } } } And the func : func getGenres(song: Song) -> [Genre] { if let genres = song.genres { return genres } else { return [] } }
Oct ’24