SwiftData Compare
Wrong:
1
2
3
4
5
monsters.forEach { monster in
if !collectedMonsters.contains(monster) {
modelContext.insert(monster)
}
}
Correct:
1
2
3
4
5
monsters.forEach { monster in
if !collectedMonsters.contains(where: { $0.no == monster.no }) {
modelContext.insert(monster)
}
}
This post is licensed under CC BY 4.0 by the author.