From b4d4ed93aa64915efb55eb50e0f336a838b13d4b Mon Sep 17 00:00:00 2001 From: tsuzukihashi Date: Sun, 19 Apr 2020 00:20:10 +0900 Subject: [PATCH] Circular reference --- Sources/NeumorphismManager.swift | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Sources/NeumorphismManager.swift b/Sources/NeumorphismManager.swift index 319be7a..f28a3a2 100644 --- a/Sources/NeumorphismManager.swift +++ b/Sources/NeumorphismManager.swift @@ -24,24 +24,33 @@ public class NeumorphismManager: NeumorphismManagable, ObservableObject { } public func setLightColor(color: Color) { - self.lightColor = color - - if !isDark { - self.color = color + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.lightColor = color + + if !self.isDark { + self.color = color + } } } public func setDarkColor(color: Color) { - self.darkColor = color - - if isDark { - self.color = color - } + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.darkColor = color + + if self.isDark { + self.color = color + } + } } public func changeMode() { - isDark.toggle() - color = isDark ? darkColor : lightColor + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.isDark.toggle() + self.color = self.isDark ? self.darkColor : self.lightColor + } UserDefaults.standard.set(isDark, forKey: "isDark") }