From 60e4b6f2c23cd0fbddfff25523c0a8242e8605ea Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 17 Jan 2023 10:01:37 -0600 Subject: [PATCH] added defaults into decode func Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Atoms/Views/TiletModel.swift | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/TiletModel.swift b/MVMCoreUI/Atomic/Atoms/Views/TiletModel.swift index 9b233e57..c3720b2b 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/TiletModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/TiletModel.swift @@ -16,9 +16,9 @@ open class TiletModel: MoleculeModelProtocol { //-------------------------------------------------- public static var identifier: String = "tilet" public var backgroundColor: Color? - public var color: TileContainer.BackgroundColor = .black - public var padding: TileContainer.Padding = .padding4X - public var aspectRatio: TileContainer.AspectRatio = .none + public var color: TileContainer.BackgroundColor + public var padding: TileContainer.Padding + public var aspectRatio: TileContainer.AspectRatio public var badge: Tilet.BadgeModel? public var title: Tilet.TitleModel? public var subTitle: Tilet.SubTitleModel? @@ -27,4 +27,20 @@ open class TiletModel: MoleculeModelProtocol { public var width: CGFloat? public var textWidth: CGFloat? public var textPercentage: CGFloat? + + required public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor) + self.color = try container.decodeIfPresent(TileContainer.BackgroundColor.self, forKey: .color) ?? TileContainer.BackgroundColor.black + self.padding = try container.decodeIfPresent(TileContainer.Padding.self, forKey: .padding) ?? TileContainer.Padding.padding4X + self.aspectRatio = try container.decodeIfPresent(TileContainer.AspectRatio.self, forKey: .aspectRatio) ?? TileContainer.AspectRatio.none + self.badge = try container.decodeIfPresent(Tilet.BadgeModel.self, forKey: .badge) + self.title = try container.decodeIfPresent(Tilet.TitleModel.self, forKey: .title) + self.subTitle = try container.decodeIfPresent(Tilet.SubTitleModel.self, forKey: .subTitle) + self.descriptiveIcon = try container.decodeIfPresent(Tilet.DescriptiveIcon.self, forKey: .descriptiveIcon) + self.directionalIcon = try container.decodeIfPresent(Tilet.DirectionalIcon.self, forKey: .directionalIcon) ?? Tilet.DirectionalIcon.init(size: .medium, surface: .dark) + self.width = try container.decodeIfPresent(CGFloat.self, forKey: .width) + self.textWidth = try container.decodeIfPresent(CGFloat.self, forKey: .textWidth) + self.textPercentage = try container.decodeIfPresent(CGFloat.self, forKey: .textPercentage) + } }