added default color in function param & removed optional properties

This commit is contained in:
Krishna Kishore Bandaru 2020-12-09 17:25:40 +05:30
parent 77b5275a44
commit 813eb68aad
3 changed files with 11 additions and 11 deletions

View File

@ -12,7 +12,7 @@ import Foundation
public override class var identifier: String { public override class var identifier: String {
return "numberedList" return "numberedList"
} }
public var numberColor: Color? public var numberColor: Color
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
@ -25,11 +25,11 @@ import Foundation
public required init(from decoder: Decoder) throws { public required init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
numberColor = try typeContainer.decodeIfPresent(Color.self, forKey: .numberColor) numberColor = try typeContainer.decodeIfPresent(Color.self, forKey: .numberColor) ?? Color(uiColor: .mvmBlack)
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list) let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
var models: [MoleculeStackItemModel] = [] var models: [MoleculeStackItemModel] = []
for (index, molecule) in list.enumerated() { for (index, molecule) in list.enumerated() {
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, stringColor: numberColor ?? Color(uiColor: .mvmBlack)))) models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: "\(index+1).", molecule: molecule, stringColor: numberColor)))
} }
super.init(molecules: models, spacing: 0) super.init(molecules: models, spacing: 0)
} }
@ -44,7 +44,7 @@ import Foundation
models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule) models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule)
} }
try container.encodeModels(models, forKey: .list) try container.encodeModels(models, forKey: .list)
try container.encodeIfPresent(numberColor, forKey: .numberColor) try container.encode(numberColor, forKey: .numberColor)
} }
} }

View File

@ -15,7 +15,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
public var molecule: MoleculeModelProtocol public var molecule: MoleculeModelProtocol
public var stringColor: Color public var stringColor: Color
public init(string: String, molecule: MoleculeModelProtocol, stringColor: Color) { public init(string: String, molecule: MoleculeModelProtocol, stringColor: Color = Color(uiColor: .mvmBlack)) {
self.string = string self.string = string
self.molecule = molecule self.molecule = molecule
self.stringColor = stringColor self.stringColor = stringColor
@ -34,7 +34,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
string = try typeContainer.decode(String.self, forKey: .string) string = try typeContainer.decode(String.self, forKey: .string)
molecule = try typeContainer.decodeModel(codingKey: .molecule) molecule = try typeContainer.decodeModel(codingKey: .molecule)
stringColor = try typeContainer.decode(Color.self, forKey: .stringColor) stringColor = try typeContainer.decodeIfPresent(Color.self, forKey: .stringColor) ?? Color(uiColor: .mvmBlack)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -43,6 +43,6 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
try container.encode(string, forKey: .string) try container.encode(string, forKey: .string)
try container.encodeModel(molecule, forKey: .molecule) try container.encodeModel(molecule, forKey: .molecule)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(stringColor, forKey: .stringColor) try container.encode(stringColor, forKey: .stringColor)
} }
} }

View File

@ -13,7 +13,7 @@ import Foundation
return "unOrderedList" return "unOrderedList"
} }
public var bulletChar = "" public var bulletChar = ""
public var bulletColor: Color? public var bulletColor: Color
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
@ -30,11 +30,11 @@ import Foundation
self.bulletChar = bulletChar self.bulletChar = bulletChar
} }
bulletColor = try typeContainer.decodeIfPresent(Color.self, forKey: .bulletColor) bulletColor = try typeContainer.decodeIfPresent(Color.self, forKey: .bulletColor) ?? Color(uiColor: .mvmBlack)
let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list) let list: [MoleculeModelProtocol] = try typeContainer.decodeModels(codingKey: .list)
var models: [MoleculeStackItemModel] = [] var models: [MoleculeStackItemModel] = []
for molecule in list { for molecule in list {
models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, stringColor: bulletColor ?? Color(uiColor: .mvmBlack)))) models.append(MoleculeStackItemModel(with: StringAndMoleculeModel(string: bulletChar, molecule: molecule, stringColor: bulletColor)))
} }
super.init(molecules: models, spacing: 0) super.init(molecules: models, spacing: 0)
} }
@ -50,6 +50,6 @@ import Foundation
models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule) models.append(((molecule as! MoleculeStackItemModel).molecule as! StringAndMoleculeModel).molecule)
} }
try container.encodeModels(models, forKey: .list) try container.encodeModels(models, forKey: .list)
try container.encodeIfPresent(bulletColor, forKey: .bulletColor) try container.encode(bulletColor, forKey: .bulletColor)
} }
} }