diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index c9a7f2f8..61e3ca3e 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -20,6 +20,7 @@ public enum ButtonSize: String, Codable { public class ButtonModel: MoleculeModelProtocol { public static var identifier: String = "button" + public var moleculeName: String? public var backgroundColor: Color? public var title: String public var action: ActionModelProtocol @@ -34,6 +35,7 @@ public class ButtonModel: MoleculeModelProtocol { } private enum CodingKeys: String, CodingKey { + case moleculeName case backgroundColor case title case action @@ -45,6 +47,8 @@ public class ButtonModel: MoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) @@ -60,6 +64,7 @@ public class ButtonModel: MoleculeModelProtocol { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encode(title, forKey: .title) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) diff --git a/MVMCoreUI/Atoms/TextFields/DateDropdownEntryFieldModel.swift b/MVMCoreUI/Atoms/TextFields/DateDropdownEntryFieldModel.swift index 4e916268..cdafc9e9 100644 --- a/MVMCoreUI/Atoms/TextFields/DateDropdownEntryFieldModel.swift +++ b/MVMCoreUI/Atoms/TextFields/DateDropdownEntryFieldModel.swift @@ -22,6 +22,7 @@ //-------------------------------------------------- private enum CodingKeys: String, CodingKey { + case moleculeName case dateFormat } @@ -38,6 +39,7 @@ public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encode(dateFormat, forKey: .dateFormat) } } diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryFieldModel.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryFieldModel.swift index 46171e41..0291066c 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryFieldModel.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryFieldModel.swift @@ -24,6 +24,7 @@ //-------------------------------------------------- private enum CodingKeys: String, CodingKey { + case moleculeName case digits case secureEntry } @@ -42,6 +43,7 @@ public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encode(digits, forKey: .digits) try container.encode(secureEntry, forKey: .secureEntry) } diff --git a/MVMCoreUI/Atoms/TextFields/ItemDropdownEntryFieldModel.swift b/MVMCoreUI/Atoms/TextFields/ItemDropdownEntryFieldModel.swift index b913f976..c247a644 100644 --- a/MVMCoreUI/Atoms/TextFields/ItemDropdownEntryFieldModel.swift +++ b/MVMCoreUI/Atoms/TextFields/ItemDropdownEntryFieldModel.swift @@ -22,6 +22,7 @@ //-------------------------------------------------- private enum CodingKeys: String, CodingKey { + case moleculeName case options } @@ -38,6 +39,7 @@ public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encode(options, forKey: .options) } } diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryFieldModel.swift b/MVMCoreUI/Atoms/TextFields/TextEntryFieldModel.swift index d890d918..27b0e933 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryFieldModel.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryFieldModel.swift @@ -28,6 +28,7 @@ //-------------------------------------------------- private enum CodingKeys: String, CodingKey { + case moleculeName case text case placeholder case enabledTextColor @@ -54,6 +55,7 @@ public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(text, forKey: .text) try container.encodeIfPresent(placeholder, forKey: .placeholder) try container.encodeIfPresent(enabledTextColor, forKey: .enabledTextColor) diff --git a/MVMCoreUI/Molecules/FooterModel.swift b/MVMCoreUI/Molecules/FooterModel.swift index 9f7b002f..d61d1194 100644 --- a/MVMCoreUI/Molecules/FooterModel.swift +++ b/MVMCoreUI/Molecules/FooterModel.swift @@ -14,6 +14,7 @@ import Foundation public var backgroundColor: Color? private enum CodingKeys: String, CodingKey { + case moleculeName case backgroundColor } @@ -48,6 +49,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } } diff --git a/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift b/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift index 5d88b913..c8124b3c 100644 --- a/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/AccordionListItemModel.swift @@ -17,7 +17,9 @@ class AccordionListItemModel: MoleculeContainerModel, ListItemModelProtocol { public var line: LineModel? private enum CodingKeys: String, CodingKey { + case moleculeName case molecules + case molecule case backgroundColor case hideLineWhenExpanded case hideArrow @@ -38,9 +40,11 @@ class AccordionListItemModel: MoleculeContainerModel, ListItemModelProtocol { public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeModels(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(hideLineWhenExpanded, forKey: .hideLineWhenExpanded) try container.encodeIfPresent(line, forKey: .line) + try container.encodeModel(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift index 8f7eea64..726d4846 100644 --- a/MVMCoreUI/Molecules/Items/CarouselItemModel.swift +++ b/MVMCoreUI/Molecules/Items/CarouselItemModel.swift @@ -19,6 +19,7 @@ import Foundation case backgroundColor case peakingUI case peakingArrowColor + case molecule } required public init(from decoder: Decoder) throws { @@ -35,5 +36,6 @@ import Foundation try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(peakingUI, forKey: .peakingUI) try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) + try container.encodeModel(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift b/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift index 13af4278..5120eb0f 100644 --- a/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/DropDownListItemModel.swift @@ -53,6 +53,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case molecules + case molecule case dropDown case line case backgroundColor @@ -79,7 +80,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeModels2D(molecules, forKey: .molecules) + try container.encodeModels2D(molecules, forKey: .molecules) try container.encode(dropDown, forKey: .dropDown) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(line, forKey: .line) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index ff9f056d..a5490651 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -10,6 +10,7 @@ import Foundation import MVMCore @objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { + public static var identifier: String = "listItem" public var backgroundColor: Color? public var action: ActionModelProtocol? @@ -20,6 +21,7 @@ import MVMCore private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case molecule case action case hideArrow case line @@ -63,6 +65,8 @@ import MVMCore public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeModel(molecule, forKey: .molecule) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModelIfPresent(action, forKey: .action) diff --git a/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift b/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift index 970f66f6..4731ef34 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift @@ -16,6 +16,7 @@ import Foundation public var gone: Bool = false private enum CodingKeys: String, CodingKey { + case moleculeName case spacing case percent case gone @@ -38,6 +39,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(spacing, forKey: .spacing) try container.encodeIfPresent(percent, forKey: .percent) try container.encode(gone, forKey: .gone) diff --git a/MVMCoreUI/Molecules/Items/TabsListItemModel.swift b/MVMCoreUI/Molecules/Items/TabsListItemModel.swift index 13dd09e7..0158774a 100644 --- a/MVMCoreUI/Molecules/Items/TabsListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/TabsListItemModel.swift @@ -18,6 +18,7 @@ public class TabsListItemModel: ContainerModel, ListItemModelProtocol { public var line: LineModel? = LineModel(type: .standard) private enum CodingKeys: String, CodingKey { + case moleculeName case tabs case molecules case backgroundColor @@ -46,6 +47,7 @@ public class TabsListItemModel: ContainerModel, ListItemModelProtocol { public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) try container.encode(tabs, forKey: .tabs) try container.encodeModels2D(molecules, forKey: .molecules) try container.encode(backgroundColor, forKey: .backgroundColor) diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index fc22f864..62199654 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -10,6 +10,7 @@ import Foundation @objcMembers public class HeadlineBodyModel: MoleculeModelProtocol { public static var identifier: String = "headlineBody" + public var moleculeName: String? public var headline: LabelModel? public var body: LabelModel? public var style: String? diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/NumberedListModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/NumberedListModel.swift index 53bec673..795eec7d 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/NumberedListModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/NumberedListModel.swift @@ -35,6 +35,7 @@ import Foundation public override func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encode(moleculeName, forKey: .moleculeName) var models: [MoleculeModelProtocol] = [] for molecule in molecules { diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/UnOrderedListModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/UnOrderedListModel.swift index 56281c43..87d57927 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/UnOrderedListModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/Lists/UnOrderedListModel.swift @@ -41,6 +41,7 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(bulletChar, forKey: .bulletChar) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encode(moleculeName, forKey: .moleculeName) var models: [MoleculeModelProtocol] = [] for molecule in molecules { diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index c4542898..d3a9f779 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -151,10 +151,10 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol var tmpMolecules = [ListItemModelProtocol]() molecules.forEach { molecule in - let data = try? JSONSerialization.data(withJSONObject: molecule) let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!) - +  let jsonData = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) + let json = String(data: data!, encoding: String.Encoding.utf8) tmpMolecules.append(listItemModel!) } @@ -180,11 +180,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol var tmpMolecules = [ListItemModelProtocol]() molecules.forEach { molecule in - let data = try? JSONSerialization.data(withJSONObject: molecule) - let decoder = JSONDecoder() - let listItemModel = try? decoder.decode(ListItemModel.self, from: data!) - + let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!) tmpMolecules.append(listItemModel!) }