From 1db2a5b05875eae13fa5b18cd871301904810754 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 18 Dec 2019 12:06:13 -0500 Subject: [PATCH] fixes --- .../Atoms/Buttons/CaretButtonModel.swift | 39 ++++++++++++++++--- .../MFTextField+ModelExtension.swift | 4 +- .../ContainerMoleculeProtocol.swift | 7 +--- .../ListItemModelProtocol.swift | 2 +- .../ModelProtocols/MoleculeProtocol.swift | 5 --- .../Models/Molecules/CarouselItemModel.swift | 9 +++-- .../Molecules/DropDownListItemModel.swift | 7 +++- MVMCoreUI/Models/Molecules/FooterModel.swift | 8 ++-- MVMCoreUI/Models/Molecules/HeaderModel.swift | 9 ++--- .../Models/Molecules/TextFieldModel.swift | 4 +- MVMCoreUI/Molecules/Items/ListItemModel.swift | 15 ++++--- .../Items/MoleculeCollectionViewCell.swift | 8 +--- .../Items/MoleculeTableViewCell.swift | 4 +- MVMCoreUI/Molecules/Items/TableViewCell.swift | 3 +- ...MoleculeMappingObject+ModelExtension.swift | 2 +- .../ModelMoleculeDelegateProtocol.swift | 4 +- .../Templates/MoleculeListTemplate.swift | 38 +++++++++--------- 17 files changed, 96 insertions(+), 72 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift index a2e42aed..c3946788 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButtonModel.swift @@ -7,19 +7,48 @@ // import Foundation - +import MVMCore public class CaretButtonModel: MoleculeProtocol { public static var identifier: String = "caretButton" public var backgroundColor: String? - public var label: String - public var action: ActionModel + public var label: LabelModel + public var action: ActionProtocol public var enabledColor: String? public var disabledColor: String? public var enabled: Bool? - - public init(label: String, action: ActionModel) { + + public init(label: LabelModel, action: ActionProtocol) { self.label = label self.action = action } + + enum CodingKeys: String, CodingKey { + case backgroundColor + case label + case action + case enabledColor + case disabledColor + case enabled + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + label = try typeContainer.decode(LabelModel.self, forKey: .label) + enabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .enabledColor) + disabledColor = try typeContainer.decodeIfPresent(String.self, forKey: .disabledColor) + enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) + action = try typeContainer.decode(codingKey: .action, typeCodingKey: ActionCodingKey.type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(label, forKey: .label) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(action, forKey: .action) + try container.encodeIfPresent(enabledColor, forKey: .enabledColor) + try container.encodeIfPresent(disabledColor, forKey: .disabledColor) + try container.encodeIfPresent(enabled, forKey: .enabled) + } } diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift index 81f00282..79ff851e 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift +++ b/MVMCoreUI/Atoms/TextFields/MFTextField+ModelExtension.swift @@ -38,7 +38,9 @@ extension MFTextField: ModelMoleculeViewProtocol { formText = textFieldModel.label as NSString? text = textFieldModel.value as NSString? - enable(textFieldModel.disabled) + if let disabled = textFieldModel.disabled { + enable(disabled) + } errMessage = textFieldModel.errorMsg fieldKey = textFieldModel.fieldKey groupName = textFieldModel.groupName diff --git a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift index f6ff152e..81ffd123 100644 --- a/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ContainerMoleculeProtocol.swift @@ -9,7 +9,7 @@ import Foundation public protocol ContainerMoleculeProtocol: MoleculeProtocol { - var molecule: MoleculeProtocol? { get } + var molecule: MoleculeProtocol { get } var useHorizontalMargins: Bool? { get } var useVerticalMargins: Bool? { get } var horizontalAlignment: String? { get } @@ -17,11 +17,6 @@ public protocol ContainerMoleculeProtocol: MoleculeProtocol { } extension ContainerMoleculeProtocol { - - public var molecule: MoleculeProtocol? { - get { return nil } - } - public var backgroundColor: String? { get { return nil } } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 59e51708..59bec9ae 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -9,6 +9,6 @@ import Foundation public protocol ListItemModelProtocol: ContainerMoleculeProtocol { - var molecule: MoleculeProtocol? { get } + var molecule: MoleculeProtocol { get } var separator: LineModel? { get set } } diff --git a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift index 53f0fee4..581f487c 100644 --- a/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/MoleculeProtocol.swift @@ -3,15 +3,10 @@ import Foundation public protocol MoleculeProtocol: Model { var moleculeName: String? { get } var backgroundColor: String? { get } - var dictionary: [AnyHashable: Any]? { get } } extension MoleculeProtocol { public var moleculeName: String? { get { return Self.identifier } } - - public var dictionary: [AnyHashable: Any]? { - return toJSON() - } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 58aa737f..eb9df665 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -11,10 +11,10 @@ import Foundation @objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { public static var identifier: String = "carouselItem" - public var backgroundColor: String? + public var molecule: MoleculeProtocol - public init(backgroundColor: String?) { - self.backgroundColor = backgroundColor + public init(molecule: MoleculeProtocol) { + self.molecule = molecule } enum CodingKeys: String, CodingKey { @@ -25,13 +25,14 @@ 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) + molecule = try typeContainer.decode(codingKey: .molecule) } 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.encode(molecule, forKey: .molecule) try container.encodeIfPresent(self.molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 7a7770df..70a9c662 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -10,17 +10,20 @@ import Foundation @objcMembers public class DropDownListItemModel: ListItemModelProtocol { public static var identifier: String = "dropDownListItem" + public var molecule: MoleculeProtocol public var molecules: [[ListItemModel]] public var backgroundColor: String? public var separator: LineModel? public var dropDown: DropDownModel - public init(molecules: [[ListItemModel]], dropDown: DropDownModel) { + public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) { + self.molecule = molecule self.molecules = molecules self.dropDown = dropDown } enum CodingKeys: String, CodingKey { + case molecule case moleculeName case molecules case separator @@ -30,6 +33,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + molecule = try typeContainer.decode(codingKey: .molecule) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) self.separator = try typeContainer.decode(LineModel.self, forKey: .separator) self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) @@ -38,6 +42,7 @@ import Foundation public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(molecule, forKey: .molecule) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) diff --git a/MVMCoreUI/Models/Molecules/FooterModel.swift b/MVMCoreUI/Models/Molecules/FooterModel.swift index 95a45422..33751aa0 100644 --- a/MVMCoreUI/Models/Molecules/FooterModel.swift +++ b/MVMCoreUI/Models/Molecules/FooterModel.swift @@ -13,11 +13,10 @@ import Foundation public static var identifier: String = "footer" public var moleculeName: String? public var backgroundColor: String? - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol - public init(molecule: MoleculeProtocol?, backgroundColor: String?){ + public init(molecule: MoleculeProtocol){ self.molecule = molecule - self.backgroundColor = backgroundColor } enum CodingKeys: String, CodingKey { @@ -31,7 +30,7 @@ import Foundation 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.molecule = try typeContainer.decode(codingKey: .molecule) } public func encode(to encoder: Encoder) throws { @@ -39,5 +38,6 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) + try container.encode(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/HeaderModel.swift b/MVMCoreUI/Models/Molecules/HeaderModel.swift index adbfca47..5212de7c 100644 --- a/MVMCoreUI/Models/Molecules/HeaderModel.swift +++ b/MVMCoreUI/Models/Molecules/HeaderModel.swift @@ -12,13 +12,11 @@ import Foundation public static var identifier: String = "header" public var moleculeName: String? public var backgroundColor: String? - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol public var seperator: LineModel? - public init(molecule: MoleculeProtocol?, backgroundColor: String?, seperator: LineModel?){ + public init(molecule: MoleculeProtocol){ self.molecule = molecule - self.backgroundColor = backgroundColor - self.seperator = seperator } enum CodingKeys: String, CodingKey { @@ -32,7 +30,7 @@ import Foundation 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.molecule = try typeContainer.decode(codingKey: .molecule) self.seperator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) } @@ -42,5 +40,6 @@ import Foundation try container.encodeIfPresent(self.molecule, forKey: .molecule) try container.encodeIfPresent(self.backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(self.seperator, forKey: .separator) + try container.encode(molecule, forKey: .molecule) } } diff --git a/MVMCoreUI/Models/Molecules/TextFieldModel.swift b/MVMCoreUI/Models/Molecules/TextFieldModel.swift index f9b11d5f..ea6f3deb 100644 --- a/MVMCoreUI/Models/Molecules/TextFieldModel.swift +++ b/MVMCoreUI/Models/Molecules/TextFieldModel.swift @@ -13,8 +13,8 @@ import UIKit public static var identifier: String = "textField" public var backgroundColor: String? - public var editable = true - public var disabled = false + public var editable: Bool? + public var disabled: Bool? public var errorMsg: String? public var label: String? public var type: String? diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 5ae9e7fa..c1fd5203 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -7,16 +7,21 @@ // import Foundation +import MVMCore @objcMembers public class ListItemModel: ListItemModelProtocol { public static var identifier: String = "listItem" - public var molecule: MoleculeProtocol? + public var molecule: MoleculeProtocol public var backgroundColor: String? - public var action: ActionModel? + public var action: ActionProtocol? public var hideArrow: Bool? public var separator: LineModel? public var style: String? + public init(molecule: MoleculeProtocol) { + self.molecule = molecule + } + enum CodingKeys: String, CodingKey { case moleculeName case molecule @@ -28,8 +33,8 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeIfPresent(codingKey: .molecule) - action = try typeContainer.decodeIfPresent(ActionModel.self, forKey: .action) + molecule = try typeContainer.decode(codingKey: .molecule) + action = try typeContainer.decodeIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) style = try typeContainer.decodeIfPresent(String.self, forKey: .style) @@ -38,7 +43,7 @@ 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.encode(molecule, forKey: .molecule) try container.encodeIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(separator, forKey: .separator) diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index bc97be16..00b8c1ee 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -90,18 +90,14 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi backgroundColor = UIColor.mfGet(forHex: backgroundColorString) } - guard let moleculeModel = collectionModel.molecule else { - return - } - if molecule == nil { - if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) { + if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(collectionModel.molecule, delegateObject, true) { contentView.insertSubview(moleculeView, at: 0) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: true).values)) molecule = moleculeView } } else { - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(collectionModel.molecule, delegateObject, additionalData) } // This molecule will handle spacing by default. diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 2e45d0f1..f3674562 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -14,7 +14,7 @@ import UIKit super.setWithModel(model, delegateObject, additionalData) guard let model = model, - let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule, + let moleculeModel = (model as? ListItemModelProtocol)?.molecule, let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(moleculeModel, delegateObject, true) else { return } @@ -22,7 +22,7 @@ import UIKit } public override class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - guard let moleculeModel = (molecule as? ContainerMoleculeProtocol)?.molecule else { + guard let moleculeModel = (molecule as? ListItemModelProtocol)?.molecule else { return "\(self)<>" } let className = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index 20c48487..216f95aa 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -179,8 +179,7 @@ import UIKit bottomSeparatorView?.setWithModel(separator, nil, nil) } - guard let moleculeModel = model.molecule else { return } - (molecule as? ModelMoleculeViewProtocol)?.setWithModel(moleculeModel, delegateObject, additionalData) + (molecule as? ModelMoleculeViewProtocol)?.setWithModel(model.molecule, delegateObject, additionalData) // This molecule will by default handle margins. if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift index 070c8680..8eda8a52 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelExtension.swift @@ -31,7 +31,7 @@ public extension MVMCoreUIMoleculeMappingObject { if let molecule = molecule as? ModelMoleculeViewProtocol { molecule.setWithModel(model, delegateObject, nil) } else { - molecule.setWithJSON?(model.dictionary, delegateObject: delegateObject, additionalData: nil) + molecule.setWithJSON?(model.toJSON(), delegateObject: delegateObject, additionalData: nil) } } diff --git a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift index 2120333e..dd79ee3d 100644 --- a/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift +++ b/MVMCoreUI/OtherHandlers/ModelMoleculeDelegateProtocol.swift @@ -9,6 +9,6 @@ import Foundation public protocol ModelMoleculeDelegateProtocol { - func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) - func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) + func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) + func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 534d3228..3ba28ecc 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -10,7 +10,7 @@ import UIKit open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol, ModelMoleculeDelegateProtocol { - public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? + public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? var observer: NSKeyValueObservation? public var templateModel: TemplateModelProtocol? @@ -139,7 +139,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - public func addMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { // This dispatch is needed to fix a race condition that can occur if this function is called during the table setup. DispatchQueue.main.async { guard let indexPath = self.tableView?.indexPath(for: sender) else { return } @@ -157,7 +157,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol self.view.layoutIfNeeded() } } - public func removeMolecules(_ molecules: [MoleculeProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { + public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] //TODO: cehck for molecule protocola eqality for molecule in molecules { @@ -172,23 +172,21 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol self.updateViewConstraints() self.view.layoutIfNeeded() } - - // MARK: - Convenience /// Returns the (identifier, class) of the molecule for the given map. - func getMoleculeInfo(with molecule: MoleculeProtocol?) -> (identifier: String, class: AnyClass, molecule: MoleculeProtocol)? { - guard let molecule = molecule, - let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(molecule), - let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: molecule, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? molecule.moleculeName else { + func getMoleculeInfo(with listItem: ListItemModelProtocol?) -> (identifier: String, class: AnyClass, molecule: ListItemModelProtocol)? { + guard let listItem = listItem, + let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem), + let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.name(forReuse: listItem, delegateObject: delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.molecule.moleculeName else { return nil } - return (moleculeName, moleculeClass, molecule) + return (moleculeName, moleculeClass, listItem) } /// Sets up the molecule list and ensures no errors loading all content. - func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)]? { - var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] + func getMoleculeInfoList() -> [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]? { + var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { for molecule in molecules { if let info = getMoleculeInfo(with: molecule) { @@ -201,14 +199,14 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol /// Sets up the header, footer, molecule list and ensures no errors loading all content. func setup() { - var moleculeList: [(identifier: String, class: AnyClass, molecule: MoleculeProtocol)] = [] - if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [MoleculeProtocol] { - for molecule in molecules { - if let info = getMoleculeInfo(with: molecule) { - moleculeList.append(info) - } - } - } + var moleculeList: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)] = [] + if let molecules = (templateModel as? ListPageTemplateModel)?.molecules { + for molecule in molecules { + if let info = getMoleculeInfo(with: molecule) { + moleculeList.append(info) + } + } + } moleculesInfo = moleculeList }