added default id to UUID

This commit is contained in:
Krishna Kishore Bandaru 2023-08-02 17:32:37 +05:30
parent 76b0810905
commit f8bc4c1167
2 changed files with 5 additions and 4 deletions

View File

@ -30,7 +30,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
public var fieldKey: String? public var fieldKey: String?
public var groupName: String = FormValidator.defaultGroupName public var groupName: String = FormValidator.defaultGroupName
public var baseValue: AnyHashable? public var baseValue: AnyHashable?
public var id: String? public var id: String
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -76,9 +76,10 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(_ state: Bool) { public init(_ state: Bool, id: String = UUID().uuidString) {
self.selected = state self.selected = state
baseValue = state baseValue = state
self.id = id
} }
//-------------------------------------------------- //--------------------------------------------------
@ -126,7 +127,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
} }
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) id = try typeContainer.decode(forKey: .id, default: { UUID().uuidString }())
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {

View File

@ -15,5 +15,5 @@ import Foundation
public protocol AccessibilityElementProtocol: Identifiable { public protocol AccessibilityElementProtocol: Identifiable {
var id: String? { get set } var id: String { get set }
} }