Name changes and cleanup

This commit is contained in:
Pfeil, Scott Robert 2019-12-17 14:12:04 -05:00
parent 77e2269062
commit e41f3039e4
5 changed files with 14 additions and 14 deletions

View File

@ -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)

View File

@ -13,22 +13,22 @@ extension KeyedDecodingContainer where Key : CodingKey {
case moleculeName
}
public func decode(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol {
return try decode(codingKey: codingKey, typeCodingKey: TypeCodingKey.moleculeName)
public func decodeMolecule(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol {
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)
public func decodeMoleculeIfPresent(codingKey: KeyedDecodingContainer<K>.Key) throws -> MoleculeProtocol? {
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 {
public func decodeMolecules(codingKey: KeyedDecodingContainer<K>.Key) throws -> [MoleculeProtocol] {
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]
}
}

View File

@ -29,12 +29,12 @@ 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.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
self.molecule = try typeContainer.decodeMoleculeIfPresent(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.encodeModelIfPresent(self.molecule, forKey: .molecule)
}
}

View File

@ -27,14 +27,14 @@ import Foundation
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
self.molecule = try typeContainer.decodeMoleculeIfPresent(codingKey: .molecule)
self.action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action)
}
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.encodeModelIfPresent(self.molecule, forKey: .molecule)
try container.encodeIfPresent(action, forKey: .action)
}
}

View File

@ -24,12 +24,12 @@ import Foundation
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.molecule = try typeContainer.decodeIfPresent(codingKey: .molecule)
self.molecule = try typeContainer.decodeMoleculeIfPresent(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.encodeModelIfPresent(self.molecule, forKey: .molecule)
}
}