fixes
This commit is contained in:
parent
b3a2511b96
commit
b076ad3316
@ -31,7 +31,7 @@ public extension MVMCoreAlertObject {
|
||||
let alert = MVMCoreAlertObject(popupAlertWithTitle: alertJson.optionalStringForKey(KeyTitle),
|
||||
message: alertJson.optionalStringForKey(KeyMessage),
|
||||
actions: actionsForAlert,
|
||||
isGreedy: true)
|
||||
isGreedy: false)
|
||||
return alert
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
public class AlertButtonModel: Codable {
|
||||
public var title: String
|
||||
public var action: ActionModelProtocol
|
||||
@ -27,16 +28,18 @@ public class AlertButtonModel: Codable {
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
if let style = try? typeContainer.decodeIfPresent(UIAlertAction.Style.self, forKey: .style) {
|
||||
self.style = style
|
||||
|
||||
if let style = try? typeContainer.decodeIfPresent(String.self, forKey: .style) {
|
||||
self.style = UIAlertAction.Style.getStyle(for: style)
|
||||
}
|
||||
|
||||
action = try typeContainer.decodeModel(codingKey: .action)
|
||||
}
|
||||
|
||||
open func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(title, forKey: .title)
|
||||
try container.encode(style, forKey: .style)
|
||||
try container.encode(UIAlertAction.Style.getStyleString(for: style), forKey: .style)
|
||||
try container.encodeModel(action, forKey: .action)
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,31 +12,72 @@ enum AlertActionError: Error {
|
||||
case notAnAlertAction
|
||||
}
|
||||
|
||||
extension UIAlertAction.Style: Codable {
|
||||
extension UIAlertAction.Style: RawRepresentable {
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.singleValueContainer()
|
||||
let int = try typeContainer.decode(Int.self)
|
||||
guard let alignment = UIAlertAction.Style(rawValue: int) else {
|
||||
guard let style = UIAlertAction.Style(rawValue: int) else {
|
||||
throw AlertActionError.notAnAlertAction
|
||||
}
|
||||
self = alignment
|
||||
self = style
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(rawValueInt)
|
||||
try container.encode(rawValueString)
|
||||
}
|
||||
|
||||
var rawValueInt: Int {
|
||||
switch self {
|
||||
case .default:
|
||||
return 0
|
||||
case .cancel:
|
||||
return 1
|
||||
case .destructive:
|
||||
return 2
|
||||
@unknown default:
|
||||
return 0
|
||||
init?(rawValue: String) {
|
||||
switch rawValue {
|
||||
case "default":
|
||||
self = .default
|
||||
case "cancel":
|
||||
self = .cancel
|
||||
case "destructive":
|
||||
self = .destructive
|
||||
default:
|
||||
self = .default
|
||||
}
|
||||
}
|
||||
|
||||
var rawValueString: String {
|
||||
switch self {
|
||||
case .default:
|
||||
return "default"
|
||||
case .cancel:
|
||||
return "cancel"
|
||||
case .destructive:
|
||||
return "destructive"
|
||||
@unknown default:
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user