remove duplicate code

This commit is contained in:
Suresh, Kamlesh 2020-07-15 20:36:34 -04:00
parent 724c1afd7c
commit 52af06fd4a
3 changed files with 4 additions and 30 deletions

View File

@ -21,7 +21,7 @@ public extension MVMCoreAlertObject {
var actionsForAlert: [UIAlertAction] = []
for actionJson in actionsList {
let style = UIAlertAction.Style.getStyle(for: actionJson.stringForkey("style"))
let style = UIAlertAction.Style(rawValue: actionJson.stringForkey("style"))
let alertAction = UIAlertAction(title: actionJson.optionalStringForKey(KeyTitle), style: style) { (action) in
MVMCoreActionHandler.shared()?.handleAction(with: actionJson.optionalDictionaryForKey("action"), additionalData: additionalData, delegateObject: delegateObject)
}

View File

@ -30,7 +30,7 @@ public class AlertButtonModel: Codable {
title = try typeContainer.decode(String.self, forKey: .title)
if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) {
self.style = UIAlertAction.Style.getStyle(for: style)
self.style = UIAlertAction.Style(rawValue: style)
}
action = try typeContainer.decodeModel(codingKey: .action)
}
@ -38,7 +38,7 @@ public class AlertButtonModel: Codable {
open func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(title, forKey: .title)
try container.encode(UIAlertAction.Style.getStyleString(for: style), forKey: .style)
try container.encode(style.rawValueString, forKey: .style)
try container.encodeModel(action, forKey: .action)
}
}

View File

@ -28,7 +28,7 @@ extension UIAlertAction.Style: Codable {
try container.encode(rawValueString)
}
init?(rawValue: String) {
init(rawValue: String) {
switch rawValue {
case "default":
self = .default
@ -53,30 +53,4 @@ extension UIAlertAction.Style: Codable {
return "default"
}
}
public static func getStyle(for string: String) -> UIAlertAction.Style {
switch string {
case "default":
return .default
case "cancel":
return .cancel
case "destructive":
return .destructive
default:
return .default
}
}
public static func getStyleString(for alignment: UIAlertAction.Style) -> String {
switch alignment {
case .default:
return "default"
case .cancel:
return "cancel"
case .destructive:
return "destructive"
default:
return "default"
}
}
}