Optimize custom font

This commit is contained in:
Thomas Ricouard 2023-02-21 07:37:16 +01:00
parent b259b6739e
commit 061791f632

View File

@ -88,11 +88,16 @@ public class Theme: ObservableObject {
} }
} }
private var _cachedChoosenFont: UIFont?
public var chosenFont: UIFont? { public var chosenFont: UIFont? {
get { get {
if let _cachedChoosenFont {
return _cachedChoosenFont
}
guard let chosenFontData, guard let chosenFontData,
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil } let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
_cachedChoosenFont = font
return font return font
} }
set { set {
@ -103,6 +108,7 @@ public class Theme: ObservableObject {
} else { } else {
chosenFontData = nil chosenFontData = nil
} }
_cachedChoosenFont = nil
} }
} }