From e3d36c1aa52f14fda61326af902c8a98ad8dd63d Mon Sep 17 00:00:00 2001 From: An Tran Date: Sun, 6 Nov 2022 16:34:35 +0700 Subject: [PATCH] Fix refreshing a scenario --- Sources/Scenarios/BaseScenariosManager.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/Scenarios/BaseScenariosManager.swift b/Sources/Scenarios/BaseScenariosManager.swift index 23d7cef..1251a63 100644 --- a/Sources/Scenarios/BaseScenariosManager.swift +++ b/Sources/Scenarios/BaseScenariosManager.swift @@ -142,10 +142,9 @@ open class BaseScenariosManager { } func setupBindings() { - let notificationCenter = NotificationCenter.default - notificationCenter.addObserver(self, selector: #selector(reset), name: .resetScenario, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reset), name: .resetScenario, object: nil) } - + func updateContent() { if let activeScenarioId = activeScenarioId { if isInitialLaunch { @@ -172,7 +171,7 @@ open class BaseScenariosManager { let previsousScenarioId = activeScenarioId activeScenarioId = nil - DispatchQueue.global().asyncAfter(deadline: .now() + 0.5) { [weak self] in + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in DispatchQueue.main.async { self?.activeScenarioId = previsousScenarioId } @@ -187,6 +186,10 @@ open class BaseScenariosManager { scenarioListLayout = .nestedList } } + + deinit { + NotificationCenter.default.removeObserver(self) + } } public protocol ScenarioPlugin {