diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift index 46503fa..d15ed80 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertObject+Swift.swift @@ -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) } diff --git a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift index b0a348d..6b4c634 100644 --- a/MVMCore/MVMCore/Models/ActionType/AlertModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/AlertModel.swift @@ -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) } } diff --git a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift index 4957cbc..df524ec 100644 --- a/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift +++ b/MVMCore/MVMCore/Models/ActionType/UIAlertActionStyle+Codable.swift @@ -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" - } - } }