action model protocol make its to optional

This commit is contained in:
Damodaram 2020-06-01 19:53:55 +05:30
parent 4ae51e4c84
commit 3b12f5942a
2 changed files with 4 additions and 4 deletions

View File

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

View File

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