I think there’s a bug in the updateTags()
method of Chapter 23 (“Core Data Relationships”), page 469.
While not stated explicitly in the text (just that the code “needs to manage the selection of tags”), I believe it’s rebuilding its selectedIndexPaths
array for the new paths, given that some of the values likely changed due to the just-added tag. Trouble is, it does not first clear the existing values from selectedIndexPaths
.
You’ll see the effect of this if a photo already has a tag, and you add a new tag alphabetically preceding it (e.g., “1”). You’ll end up with a checkmark for the correct tag, plus a checkmark for the tag at the prior (uncleared) indexPath.
It’s easy enough to fix: before the switch
in updateTags
, add:
self.selectedIndexPaths.removeAll(keepingCapacity: true)