diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift index 992cce53..88ae728d 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift @@ -14,14 +14,20 @@ import UIKit } var style: String? + var name: String? + var size: CGFloat? private enum CodingKeys: String, CodingKey { case style + case name + case size } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + self.name = try typeContainer.decodeIfPresent(String.self, forKey: .name) + self.size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) try super.init(from: decoder) } @@ -29,5 +35,7 @@ import UIKit try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(style, forKey: .style) + try container.encodeIfPresent(name, forKey: .name) + try container.encodeIfPresent(size, forKey: .size) } } diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift index e47a395f..b4c71153 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift @@ -56,22 +56,25 @@ import Foundation self.fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) self.fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) self.textAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .textAlignment) - do { - var attributesContainer = try typeContainer.nestedUnkeyedContainer(forKey: .attributes) - var attributes = [LabelAttributeModel]() - while !attributesContainer.isAtEnd { - guard let attmodel = try attributesContainer.decodeUnKeyedIfPresent(LabelAttributeModel.self, typeCodingKey: AttributeTypeKey.type) else { - continue - } - attributes.append(attmodel) - } - self.attributes = attributes - } catch { - print("no attributes") - } + self.attributes = try typeContainer.decodeArrayIfPresent(codingKey: .attributes, typeCodingKey: AttributeTypeKey.type) as? [LabelAttributeModel] self.html = try typeContainer.decodeIfPresent(String.self, forKey: .html) self.hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero) self.makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable) + /*if let atts = self.attributes { + for attribute in atts { + switch attribute.type { + case "font": + let afont = attribute as? LabelAttributeFontModel + print("font length\(afont!.length), \(String(describing: afont?.name))") + case "color": + let afont = attribute as? LabelAttributeColorModel + print("font length\(afont!.length), \(String(describing: afont?.textColor))") + default: + print("attribute") + } + + } + } */ } public func encode(to encoder: Encoder) throws {