action model protocol make its to optional
This commit is contained in:
parent
4ae51e4c84
commit
3b12f5942a
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user