So I completed the app and it worked exactly how it is supposed to. I decided to play around to see if there were any parts I could change using knowledge I already knew, and that is when I ran into this weird problem.
struct Activity: Codable, Identifiable, Equatable {
var id = UUID()
let title: String
let description: String
var completedCount = 0
static func ==(lhs: Activity, rhs: Activity) -> Bool {
lhs.id == rhs.id
}
}
The method that updates the count for each activity:
func increment(activity: Activity) {
var copy = activity
copy.completedCount += 1
if let index = activities.firstIndex(where: { $0 == activity }) {
print("Index found at ", index)
activities[index] = copy
}
}
See after adding my own method to check for equality it stopped working! when I increment the counter UI doesn't change, no matter how many times I increment it. But when I relaunch the app I see it has incremented by 1.
Does anybody have any idea what is going on? Because if I remove the static equality method it works again.