models encode properly
This commit is contained in:
parent
6139f31e54
commit
304b4cbc4c
@ -20,6 +20,7 @@ public enum ButtonSize: String, Codable {
|
|||||||
|
|
||||||
public class ButtonModel: MoleculeModelProtocol {
|
public class ButtonModel: MoleculeModelProtocol {
|
||||||
public static var identifier: String = "button"
|
public static var identifier: String = "button"
|
||||||
|
public var moleculeName: String?
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var title: String
|
public var title: String
|
||||||
public var action: ActionModelProtocol
|
public var action: ActionModelProtocol
|
||||||
@ -34,6 +35,7 @@ public class ButtonModel: MoleculeModelProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case title
|
case title
|
||||||
case action
|
case action
|
||||||
@ -45,6 +47,8 @@ public class ButtonModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
||||||
|
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||||
@ -60,6 +64,7 @@ public class ButtonModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(title, forKey: .title)
|
try container.encode(title, forKey: .title)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeModel(action, forKey: .action)
|
try container.encodeModel(action, forKey: .action)
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case dateFormat
|
case dateFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(dateFormat, forKey: .dateFormat)
|
try container.encode(dateFormat, forKey: .dateFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case digits
|
case digits
|
||||||
case secureEntry
|
case secureEntry
|
||||||
}
|
}
|
||||||
@ -42,6 +43,7 @@
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(digits, forKey: .digits)
|
try container.encode(digits, forKey: .digits)
|
||||||
try container.encode(secureEntry, forKey: .secureEntry)
|
try container.encode(secureEntry, forKey: .secureEntry)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case options
|
case options
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(options, forKey: .options)
|
try container.encode(options, forKey: .options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case text
|
case text
|
||||||
case placeholder
|
case placeholder
|
||||||
case enabledTextColor
|
case enabledTextColor
|
||||||
@ -54,6 +55,7 @@
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(text, forKey: .text)
|
try container.encodeIfPresent(text, forKey: .text)
|
||||||
try container.encodeIfPresent(placeholder, forKey: .placeholder)
|
try container.encodeIfPresent(placeholder, forKey: .placeholder)
|
||||||
try container.encodeIfPresent(enabledTextColor, forKey: .enabledTextColor)
|
try container.encodeIfPresent(enabledTextColor, forKey: .enabledTextColor)
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import Foundation
|
|||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ import Foundation
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,9 @@ class AccordionListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
|||||||
public var line: LineModel?
|
public var line: LineModel?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case molecules
|
case molecules
|
||||||
|
case molecule
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case hideLineWhenExpanded
|
case hideLineWhenExpanded
|
||||||
case hideArrow
|
case hideArrow
|
||||||
@ -38,9 +40,11 @@ class AccordionListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeModels(molecules, forKey: .molecules)
|
try container.encodeModels(molecules, forKey: .molecules)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(hideLineWhenExpanded, forKey: .hideLineWhenExpanded)
|
try container.encodeIfPresent(hideLineWhenExpanded, forKey: .hideLineWhenExpanded)
|
||||||
try container.encodeIfPresent(line, forKey: .line)
|
try container.encodeIfPresent(line, forKey: .line)
|
||||||
|
try container.encodeModel(molecule, forKey: .molecule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import Foundation
|
|||||||
case backgroundColor
|
case backgroundColor
|
||||||
case peakingUI
|
case peakingUI
|
||||||
case peakingArrowColor
|
case peakingArrowColor
|
||||||
|
case molecule
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
@ -35,5 +36,6 @@ import Foundation
|
|||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
|
try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
|
||||||
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)
|
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)
|
||||||
|
try container.encodeModel(molecule, forKey: .molecule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,6 +53,7 @@ import Foundation
|
|||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case molecules
|
case molecules
|
||||||
|
case molecule
|
||||||
case dropDown
|
case dropDown
|
||||||
case line
|
case line
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
@ -79,7 +80,7 @@ import Foundation
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
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.encode(dropDown, forKey: .dropDown)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeIfPresent(line, forKey: .line)
|
try container.encodeIfPresent(line, forKey: .line)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import Foundation
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "listItem"
|
public static var identifier: String = "listItem"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
@ -20,6 +21,7 @@ import MVMCore
|
|||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case molecule
|
||||||
case action
|
case action
|
||||||
case hideArrow
|
case hideArrow
|
||||||
case line
|
case line
|
||||||
@ -63,6 +65,8 @@ import MVMCore
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encodeModel(molecule, forKey: .molecule)
|
||||||
|
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeModelIfPresent(action, forKey: .action)
|
try container.encodeModelIfPresent(action, forKey: .action)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import Foundation
|
|||||||
public var gone: Bool = false
|
public var gone: Bool = false
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case spacing
|
case spacing
|
||||||
case percent
|
case percent
|
||||||
case gone
|
case gone
|
||||||
@ -38,6 +39,7 @@ import Foundation
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||||
try container.encodeIfPresent(percent, forKey: .percent)
|
try container.encodeIfPresent(percent, forKey: .percent)
|
||||||
try container.encode(gone, forKey: .gone)
|
try container.encode(gone, forKey: .gone)
|
||||||
|
|||||||
@ -18,6 +18,7 @@ public class TabsListItemModel: ContainerModel, ListItemModelProtocol {
|
|||||||
public var line: LineModel? = LineModel(type: .standard)
|
public var line: LineModel? = LineModel(type: .standard)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case tabs
|
case tabs
|
||||||
case molecules
|
case molecules
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
@ -46,6 +47,7 @@ public class TabsListItemModel: ContainerModel, ListItemModelProtocol {
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(tabs, forKey: .tabs)
|
try container.encode(tabs, forKey: .tabs)
|
||||||
try container.encodeModels2D(molecules, forKey: .molecules)
|
try container.encodeModels2D(molecules, forKey: .molecules)
|
||||||
try container.encode(backgroundColor, forKey: .backgroundColor)
|
try container.encode(backgroundColor, forKey: .backgroundColor)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import Foundation
|
|||||||
|
|
||||||
@objcMembers public class HeadlineBodyModel: MoleculeModelProtocol {
|
@objcMembers public class HeadlineBodyModel: MoleculeModelProtocol {
|
||||||
public static var identifier: String = "headlineBody"
|
public static var identifier: String = "headlineBody"
|
||||||
|
public var moleculeName: String?
|
||||||
public var headline: LabelModel?
|
public var headline: LabelModel?
|
||||||
public var body: LabelModel?
|
public var body: LabelModel?
|
||||||
public var style: String?
|
public var style: String?
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import Foundation
|
|||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|
||||||
var models: [MoleculeModelProtocol] = []
|
var models: [MoleculeModelProtocol] = []
|
||||||
for molecule in molecules {
|
for molecule in molecules {
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import Foundation
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(bulletChar, forKey: .bulletChar)
|
try container.encode(bulletChar, forKey: .bulletChar)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
|
|
||||||
var models: [MoleculeModelProtocol] = []
|
var models: [MoleculeModelProtocol] = []
|
||||||
for molecule in molecules {
|
for molecule in molecules {
|
||||||
|
|||||||
@ -151,10 +151,10 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
var tmpMolecules = [ListItemModelProtocol]()
|
var tmpMolecules = [ListItemModelProtocol]()
|
||||||
|
|
||||||
molecules.forEach { molecule in
|
molecules.forEach { molecule in
|
||||||
|
|
||||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
||||||
let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!)
|
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!)
|
tmpMolecules.append(listItemModel!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +180,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
var tmpMolecules = [ListItemModelProtocol]()
|
var tmpMolecules = [ListItemModelProtocol]()
|
||||||
|
|
||||||
molecules.forEach { molecule in
|
molecules.forEach { molecule in
|
||||||
|
|
||||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
||||||
let decoder = JSONDecoder()
|
let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!)
|
||||||
let listItemModel = try? decoder.decode(ListItemModel.self, from: data!)
|
|
||||||
|
|
||||||
tmpMolecules.append(listItemModel!)
|
tmpMolecules.append(listItemModel!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user