add codable method to avoid set actionType value
This commit is contained in:
parent
0f6ded4591
commit
a2c73d9d7d
@ -18,4 +18,26 @@ import UIKit
|
|||||||
public var analyticsData: JSONValueDictionary?
|
public var analyticsData: JSONValueDictionary?
|
||||||
|
|
||||||
public var title: String?
|
public var title: String?
|
||||||
|
|
||||||
|
public enum CodingKeys: String, CodingKey {
|
||||||
|
case actionType
|
||||||
|
case title
|
||||||
|
case extraParameters
|
||||||
|
case analyticsData
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init(from decoder: Decoder) throws {
|
||||||
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
title = try typeContainer.decodeIfPresent(String.self, forKey: .title)
|
||||||
|
extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters)
|
||||||
|
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
var encoderContainer = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try encoderContainer.encodeIfPresent(actionType, forKey: .actionType)
|
||||||
|
try encoderContainer.encodeIfPresent(title, forKey: .title)
|
||||||
|
try encoderContainer.encodeIfPresent(extraParameters, forKey: .extraParameters)
|
||||||
|
try encoderContainer.encodeIfPresent(analyticsData, forKey: .analyticsData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import Foundation
|
|||||||
@objcMembers public class ActionTopAlertModel: ActionModelProtocol {
|
@objcMembers public class ActionTopAlertModel: ActionModelProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "topAlert"
|
public static var identifier: String = "topAlert"
|
||||||
public var actionType: String? = ActionTopAlertModel.identifier
|
public var actionType: String?
|
||||||
public var pageType: String
|
public var pageType: String
|
||||||
public var extraParameters: JSONValueDictionary?
|
public var extraParameters: JSONValueDictionary?
|
||||||
public var analyticsData: JSONValueDictionary?
|
public var analyticsData: JSONValueDictionary?
|
||||||
@ -21,4 +21,31 @@ import Foundation
|
|||||||
public init(pageType: String) {
|
public init(pageType: String) {
|
||||||
self.pageType = pageType
|
self.pageType = pageType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CodingKeys: String, CodingKey {
|
||||||
|
case actionType
|
||||||
|
case pageType
|
||||||
|
case title
|
||||||
|
case extraParameters
|
||||||
|
case analyticsData
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init(from decoder: Decoder) throws {
|
||||||
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
pageType = try typeContainer.decode(String.self, forKey: .pageType)
|
||||||
|
title = try typeContainer.decodeIfPresent(String.self, forKey: .title)
|
||||||
|
extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters)
|
||||||
|
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
var encoderContainer = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try encoderContainer.encodeIfPresent(actionType, forKey: .actionType)
|
||||||
|
try encoderContainer.encode(pageType, forKey: .pageType)
|
||||||
|
try encoderContainer.encodeIfPresent(title, forKey: .title)
|
||||||
|
try encoderContainer.encodeIfPresent(extraParameters, forKey: .extraParameters)
|
||||||
|
try encoderContainer.encodeIfPresent(analyticsData, forKey: .analyticsData)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user