From 3b12f5942a2408399cbb2510149be99027a67751 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Mon, 1 Jun 2020 19:53:55 +0530 Subject: [PATCH] action model protocol make its to optional --- MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift | 6 +++--- MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift index b2154925..a6ee8685 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagModel.swift @@ -10,7 +10,7 @@ import Foundation @objcMembers public class TagModel: MoleculeModelProtocol { public static var identifier: String = "tag" public var label: LabelModel - public var action: ActionModelProtocol + public var action: ActionModelProtocol? public var backgroundColor: Color? private enum CodingKeys: String, CodingKey { @@ -24,14 +24,14 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) label = try typeContainer.decode(LabelModel.self, forKey: .label) - action = try typeContainer.decodeModel(codingKey: .action) + action = try typeContainer.decodeModelIfPresent(codingKey: .action) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(label, forKey: .label) - try container.encodeModel(action, forKey: .action) + try container.encodeModelIfPresent(action, forKey: .action) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift index 2be81d56..f79d4290 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/TagsList.swift @@ -108,7 +108,7 @@ extension TagsList: UICollectionViewDelegate { open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let tagModel = tags?[indexPath.row] else {return} - if let data = try? tagModel.action.encode(using: JSONEncoder()), + if let data = try? tagModel.action?.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any]{ MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: delegateObject) }