Skip to content

Commit c8b3088

Browse files
author
Achyut Kumar M
committed
correct the logic for storing hidden elements
1 parent 4a5cf42 commit c8b3088

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ class MapViewModel: ObservableObject {
102102
if let toBeHidden = self.items.first(where: {$0.id == Int(questId)!}) {
103103
let index = self.items.firstIndex(where: {$0.id == Int(questId)!})
104104
items[index!].isHidden = true
105-
106-
var hiddenElements = [Int64]()
107-
108-
hiddenElements.append(toBeHidden.id)
109-
UserDefaults.standard.set(hiddenElements, forKey: "hiddenElements")
105+
106+
var hiddenElementIds = UserDefaults.standard.array(forKey: "hiddenElements") as? [Int64] ?? []
107+
108+
if !hiddenElementIds.contains(toBeHidden.id) {
109+
hiddenElementIds.append(toBeHidden.id)
110+
UserDefaults.standard.set(hiddenElementIds, forKey: "hiddenElements")
111+
}
110112

111113
}
112114

0 commit comments

Comments
 (0)