I’ve this perform that fetches TVShow from the TMDB API with all of its seasons.
func fetchShow(withId id: Int, fromSeason begin: Int) async throws -> Present {
let seasonStep = 14
let finish = begin + seasonStep
let fetchedShow = attempt await TMDB.TVShow(id: id, begin: begin, finish: finish)
if fetchedShow.numberOfSeasons! > finish {
let seasonLayer = attempt await fetchShow(withId: id, fromSeason: finish)
fetchedShow.seasons.append(contentsOf: seasonLayer.seasons)
} else {
return fetchedShow
}
return fetchedShow
}
Some exhibits have many seasons, and I fetch them individually, and simply the brand new seasons go to the TV present. Nevertheless, I’ve discovered that when utilizing SwiftData with Decodable @Mannequin, I get this error: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1c3c6203c)
which I came upon is only a unhealthy option to say that I can not modify the mannequin object earlier than saving it to the database. The issue is that this line of code.
fetchedShow.seasons.append(contentsOf: seasonLayer.seasons)
Is there every other resolution to this apart from saving it earlier than doing something? I’ve a search function, and it looks as if a reasonably bizarre concept to retailer each consequence with SwiftData.