identifiable streamlining

iCloud fix
This commit is contained in:
Scott Pfeil 2023-03-03 17:13:50 -05:00
parent f7f9731209
commit f8c6a11199

View File

@ -7,12 +7,13 @@
// //
@objcMembers open class LabelModel: MoleculeModelProtocol { @objcMembers open class LabelModel: MoleculeModelProtocol, Identifiable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
open class var identifier: String { "label" } open class var identifier: String { "label" }
public var id: String
public var backgroundColor: Color? public var backgroundColor: Color?
public var text: String public var text: String
public var accessibilityText: String? public var accessibilityText: String?
@ -34,6 +35,7 @@
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case id
case text case text
case accessibilityText case accessibilityText
case textColor case textColor
@ -58,7 +60,8 @@
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(text: String) { public init(id: String = UUID().uuidString, text: String) {
self.id = id
self.text = text self.text = text
} }
@ -78,6 +81,7 @@
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
text = try typeContainer.decode(String.self, forKey: .text) text = try typeContainer.decode(String.self, forKey: .text)
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
@ -102,6 +106,7 @@
open func encode(to encoder: Encoder) throws { open func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(id, forKey: .id)
try container.encode(text, forKey: .text) try container.encode(text, forKey: .text)
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
try container.encodeIfPresent(textColor, forKey: .textColor) try container.encodeIfPresent(textColor, forKey: .textColor)