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? {
get {
if let _cachedChoosenFont {
return _cachedChoosenFont
}
guard let chosenFontData,
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
_cachedChoosenFont = font
return font
}
set {
@ -103,6 +108,7 @@ public class Theme: ObservableObject {
} else {
chosenFontData = nil
}
_cachedChoosenFont = nil
}
}