ChWebsiteApp/CHDataManagement/Model/ContentLabel.swift
2025-05-02 22:11:43 +02:00

43 lines
823 B
Swift

import Foundation
struct ContentLabel {
var icon: PageIcon
var value: String
}
extension ContentLabel: Equatable {
static func == (lhs: ContentLabel, rhs: ContentLabel) -> Bool {
lhs.icon == rhs.icon && lhs.value == rhs.value
}
}
extension ContentLabel: Identifiable {
var id: String {
icon.rawValue + value
}
}
extension ContentLabel {
var data: Data {
.init(icon: icon.rawValue, value: value)
}
init?(context: LoadingContext, data: Data) {
guard let icon = PageIcon(rawValue: data.icon) else {
context.error("Unknown label icon '\(data.icon)'")
return nil
}
self.init(icon: icon, value: data.value)
}
struct Data: Codable, Equatable {
let icon: String
let value: String
}
}