update encode decode method
This commit is contained in:
parent
c6d5775d57
commit
d17ab73d34
@ -10,11 +10,8 @@ import Foundation
|
||||
|
||||
@objcMembers public class CaretViewModel: MoleculeProtocol {
|
||||
|
||||
public static var identifier: String {
|
||||
get{ return "caretView" }
|
||||
}
|
||||
public static var identifier: String = "caretView"
|
||||
public var backgroundColor: String?
|
||||
|
||||
public var strokeColor: String?
|
||||
public var isHidden: Bool?
|
||||
public var isOpaque: Bool?
|
||||
|
||||
@ -57,7 +57,7 @@ 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)
|
||||
self.attributes = try typeContainer.decodeArrayIfPresent(codingKey: .attributes, typeCodingKey: AttributeTypeKey.type) as? [LabelAttributeModel]
|
||||
self.attributes = try typeContainer.decodeModelsIfPresent(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)
|
||||
|
||||
@ -57,7 +57,7 @@ import Foundation
|
||||
}
|
||||
isRounded = progressBarModel.isRounded ?? false
|
||||
thickness = progressBarModel.thickness ?? 8
|
||||
progress = (progressBarModel.percentage )/100.0
|
||||
progress = (progressBarModel.percentage)/100.0
|
||||
if let progressColor = progressBarModel.progressColor {
|
||||
progressTintColor = UIColor.mfGet(forHex: progressColor)
|
||||
}
|
||||
|
||||
@ -14,21 +14,21 @@ extension KeyedDecodingContainer where Key : CodingKey {
|
||||
}
|
||||
|
||||
public func decode(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol {
|
||||
return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
|
||||
return try decodeModel(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
|
||||
}
|
||||
|
||||
public func decodeIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol? {
|
||||
return try decodeIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
|
||||
return try decodeModelIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
|
||||
}
|
||||
|
||||
public func decodeArray(codingKey: KeyedDecodingContainer<K>.Key) throws -> [MoleculeProtocol] {
|
||||
guard let models = try decodeArray(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else {
|
||||
guard let models = try decodeModels(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol] else {
|
||||
throw ModelRegistry.Error.decoderError
|
||||
}
|
||||
return models
|
||||
}
|
||||
|
||||
public func decodeArrayIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> [MoleculeProtocol]? {
|
||||
return try decodeArrayIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol]
|
||||
return try decodeModelsIfPresent(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName) as? [MoleculeProtocol]
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,10 +13,6 @@ import Foundation
|
||||
public static var identifier: String = "carouselItem"
|
||||
public var backgroundColor: String?
|
||||
|
||||
public init(backgroundColor: String?) {
|
||||
self.backgroundColor = backgroundColor
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecule
|
||||
@ -25,13 +21,13 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor)
|
||||
backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeModelIfPresent(molecule, forKey: .molecule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,16 +21,8 @@ import UIKit
|
||||
public var itemAlignment: String?
|
||||
public var pagingMolecule: PagingMoleculeProtocol?
|
||||
|
||||
public init(molecules: [CarouselItemModel], spacing: Float?, border: Bool?, loop: Bool?, height: Float?, itemWidthPercent: Float?, itemAlignment: String?, pagingMolecule: PagingMoleculeProtocol?, backgroundColor: String?){
|
||||
public init(molecules: [CarouselItemModel]){
|
||||
self.molecules = molecules
|
||||
self.spacing = spacing
|
||||
self.border = border
|
||||
self.loop = loop
|
||||
self.height = height
|
||||
self.itemWidthPercent = itemWidthPercent
|
||||
self.itemAlignment = itemAlignment
|
||||
self.pagingMolecule = pagingMolecule
|
||||
self.backgroundColor = backgroundColor
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
@ -47,26 +39,26 @@ import UIKit
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules)
|
||||
self.spacing = try typeContainer.decode(Float.self, forKey: .spacing)
|
||||
self.border = try typeContainer.decode(Bool.self, forKey: .border)
|
||||
self.loop = try typeContainer.decode(Bool.self, forKey: .loop)
|
||||
self.height = try typeContainer.decode(Float.self, forKey: .height)
|
||||
self.itemWidthPercent = try typeContainer.decode(Float.self, forKey: .itemWidthPercent)
|
||||
self.itemAlignment = try typeContainer.decode(String.self, forKey: .itemAlignment)
|
||||
self.pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol
|
||||
molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules)
|
||||
spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing)
|
||||
border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border)
|
||||
loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop)
|
||||
height = try typeContainer.decodeIfPresent(Float.self, forKey: .height)
|
||||
itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent)
|
||||
itemAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .itemAlignment)
|
||||
pagingMolecule = try typeContainer.decodeIfPresent(codingKey: .pagingMolecule) as? PagingMoleculeProtocol
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(molecules, forKey: .molecules)
|
||||
try container.encode(spacing, forKey: .spacing)
|
||||
try container.encode(border, forKey: .border)
|
||||
try container.encode(loop, forKey: .loop)
|
||||
try container.encode(height, forKey: .height)
|
||||
try container.encode(itemWidthPercent, forKey: .itemWidthPercent)
|
||||
try container.encode(itemAlignment, forKey: .itemAlignment)
|
||||
try container.encodeIfPresent(self.pagingMolecule, forKey: .pagingMolecule)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(border, forKey: .border)
|
||||
try container.encodeIfPresent(loop, forKey: .loop)
|
||||
try container.encodeIfPresent(height, forKey: .height)
|
||||
try container.encodeIfPresent(itemWidthPercent, forKey: .itemWidthPercent)
|
||||
try container.encodeIfPresent(itemAlignment, forKey: .itemAlignment)
|
||||
try container.encodeModelIfPresent(pagingMolecule, forKey: .pagingMolecule)
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,14 +31,14 @@ import Foundation
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules)
|
||||
self.separator = try typeContainer.decode(LineModel.self, forKey: .separator)
|
||||
self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
|
||||
try container.encode(molecules, forKey: .molecules)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(dropDown, forKey: .dropDown)
|
||||
|
||||
@ -15,29 +15,23 @@ import Foundation
|
||||
public var backgroundColor: String?
|
||||
public var molecule: MoleculeProtocol?
|
||||
|
||||
public init(molecule: MoleculeProtocol?, backgroundColor: String?){
|
||||
self.molecule = molecule
|
||||
self.backgroundColor = backgroundColor
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecule
|
||||
case backgroundColor
|
||||
case separator
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeModelIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,12 +15,6 @@ import Foundation
|
||||
public var molecule: MoleculeProtocol?
|
||||
public var seperator: LineModel?
|
||||
|
||||
public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){
|
||||
self.molecule = molecule
|
||||
self.backgroundColor = backgroundColor
|
||||
self.seperator = seperator
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecule
|
||||
@ -30,17 +24,17 @@ import Foundation
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(self.seperator, forKey: .separator)
|
||||
try container.encodeModelIfPresent(molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(seperator, forKey: .separator)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,12 +52,11 @@ import Foundation
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(self.molecule, forKey: .molecule)
|
||||
|
||||
try container.encode(spacing, forKey: .spacing)
|
||||
try container.encode(percentage, forKey: .percentage)
|
||||
try container.encode(verticalAlignment, forKey: .verticalAlignment)
|
||||
try container.encode(horizontalAlignment, forKey: .horizontalAlignment)
|
||||
try container.encode(gone, forKey: .gone)
|
||||
try container.encodeModelIfPresent(self.molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(percentage, forKey: .percentage)
|
||||
try container.encodeIfPresent(verticalAlignment, forKey: .verticalAlignment)
|
||||
try container.encodeIfPresent(horizontalAlignment, forKey: .horizontalAlignment)
|
||||
try container.encodeIfPresent(gone, forKey: .gone)
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,31 +16,28 @@ import Foundation
|
||||
public var axis: String?
|
||||
public var spacing: Float?
|
||||
|
||||
public init(axis: String?, molecules: [MoleculeStackItemModel]?, spacing: Float?) {
|
||||
self.axis = axis
|
||||
self.molecules = molecules
|
||||
self.spacing = spacing
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecules
|
||||
case axis
|
||||
case spacing
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules)
|
||||
self.axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis)
|
||||
self.spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing)
|
||||
molecules = try typeContainer.decodeIfPresent([MoleculeStackItemModel].self, forKey: .molecules)
|
||||
axis = try typeContainer.decodeIfPresent(String.self, forKey: .axis)
|
||||
spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing)
|
||||
backgroundColor = try typeContainer.decode(String.self, forKey: .backgroundColor)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(molecules, forKey: .molecules)
|
||||
try container.encode(axis, forKey: .axis)
|
||||
try container.encode(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(axis, forKey: .axis)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ import Foundation
|
||||
try container.encode(pageType, forKey: .pageType)
|
||||
try container.encode(screenHeading, forKey: .screenHeading)
|
||||
|
||||
try container.encodeArray(molecules, forKey: .molecules)
|
||||
try container.encodeModels(molecules, forKey: .molecules)
|
||||
try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs)
|
||||
try container.encodeIfPresent(header, forKey: .header)
|
||||
try container.encodeIfPresent(footer, forKey: .footer)
|
||||
|
||||
@ -20,6 +20,7 @@ import Foundation
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case molecule
|
||||
case backgroundColor
|
||||
case action
|
||||
case hideArrow
|
||||
case separator
|
||||
@ -29,6 +30,7 @@ import Foundation
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action)
|
||||
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
|
||||
separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator)
|
||||
@ -38,7 +40,8 @@ import Foundation
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(molecule, forKey: .molecule)
|
||||
try container.encodeModelIfPresent(molecule, forKey: .molecule)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(action, forKey: .action)
|
||||
try container.encodeIfPresent(hideArrow, forKey: .hideArrow)
|
||||
try container.encodeIfPresent(separator, forKey: .separator)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user