Skip to content

Commit 3eec0ee

Browse files
committed
fixed unowned crash issues
1 parent de052e6 commit 3eec0ee

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

GoInfoGame/GoInfoGame/UI/InitialView/InitialViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class InitialViewModel: ObservableObject {
6969

7070
isLoading = true
7171

72-
ApiManager.shared.performRequest(to: .fetchLongQuests(workspaceId), setupType: .workspace, modelType: LongFormResponse.self) { [unowned self] result in
72+
ApiManager.shared.performRequest(to: .fetchLongQuests(workspaceId), setupType: .workspace, modelType: LongFormResponse.self) { [weak self] result in
73+
guard let self = self else { return completion(false, "Object memory released.") }
7374
DispatchQueue.main.async { [unowned self] in
7475
switch result {
7576
case .success(let longQuestsResponse):

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ class MapViewModel: ObservableObject {
114114

115115
if let workspaceID = KeychainManager.load(key: "workspaceID") {
116116
debugPrint("requested: start \(Date())")
117-
ApiManager.shared.performRequest(to: .fetchOSMElements(bBox.minLon, bBox.minLat, bBox.maxLon, bBox.maxLat, workspaceID), setupType: .osm, modelType: OSMMapDataResponse.self) { [unowned self] result in
117+
ApiManager.shared.performRequest(to: .fetchOSMElements(bBox.minLon, bBox.minLat, bBox.maxLon, bBox.maxLat, workspaceID), setupType: .osm, modelType: OSMMapDataResponse.self) { [weak self] result in
118+
guard let self = self else {
119+
return
120+
}
118121
switch result {
119122
case .success(let success):
120123
debugPrint("response sucess: start \(Date())")
@@ -127,10 +130,10 @@ class MapViewModel: ObservableObject {
127130
debugPrint("fetchQuestsFromDB: start \(Date())")
128131
let items = AppQuestManager.shared.fetchQuestsFromDB()
129132
debugPrint("fetchQuestsFromDB: end \(Date())")
130-
DispatchQueue.main.async { [unowned self, items] in
131-
self.items = items
132-
self.isLoading = false
133-
if self.items.count == 0 {self.refreshMap = UUID()}
133+
DispatchQueue.main.async { [weak self, items] in
134+
self?.items = items
135+
self?.isLoading = false
136+
if self?.items.count == 0 {self?.refreshMap = UUID()}
134137
}
135138
debugPrint("response sucess: end \(Date())")
136139
case .failure(let failure):

0 commit comments

Comments
 (0)