Thank you all people who viewed and maybe put some thought in this. I did not stop thinking about it myself, and found out what the issue was.
Basically I was believing that Identifiable was used to identify single items in the collection (Array), but it is actually Hashable. So it's not the id that's used as the identification of an item in the collection.
A part of my app that I did not show (I didn't want to make this question more TL;DR than it already was), is that: if a selection is made, I update my datasource.
That means that my datasource has a new bunch of FileManagerItemModel items, which all have the same id as in the collection, but not the same hashValue. And so, even though the ids are the same as before, the items could not be matched anymore because the hashValues changed.
The quick solution is to add this to FileManagerItemModel:
override var hash: Int {
id.absoluteString.hashValue
}
And change the .contains check into this:
multiSelectedItems.contains(where: { $0.hashValue == item.hashValue })
But this is not going to be the final implementation. Now that I understand my mistake, I should be able to make a cleaner solution.
Thank you for thinking with me. Even though nobody had time to reply anything, surely one of you thought 'maybe hash value?', and synchronicity took care of the rest. ;)
Topic:
Programming Languages
SubTopic:
Swift