From ef7116d0bf89a39e8deb2efe79d8f10881205dae Mon Sep 17 00:00:00 2001 From: Dallas Groot Date: Sat, 11 Apr 2026 01:41:58 -0700 Subject: [PATCH] quick fix --- iOS/Views/Companion/ConflictModels.swift | 64 +++++++++++++----------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/iOS/Views/Companion/ConflictModels.swift b/iOS/Views/Companion/ConflictModels.swift index 6887a9f..d13e792 100644 --- a/iOS/Views/Companion/ConflictModels.swift +++ b/iOS/Views/Companion/ConflictModels.swift @@ -1,7 +1,37 @@ +import Foundation import SwiftUI +// MARK: - AnyCodable +// Wraps heterogeneous values in the fix_data dictionary (String, Int, or [String]). +// Must be defined before CompanionAPIService extension references it. + +struct AnyCodable: Codable { + let value: Any + + init(_ value: Any) { self.value = value } + + init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + if let v = try? container.decode([String].self) { value = v; return } + if let v = try? container.decode([String: String].self) { value = v; return } + if let v = try? container.decode(String.self) { value = v; return } + if let v = try? container.decode(Int.self) { value = v; return } + value = "" + } + + func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + switch value { + case let v as [String]: try container.encode(v) + case let v as [String: String]: try container.encode(v) + case let v as String: try container.encode(v) + case let v as Int: try container.encode(v) + default: try container.encode("") + } + } +} + // MARK: - Conflict Models -// Kept in a separate file so both CompanionAPIService and LibraryConflictsView can reference these types. struct LibraryConflict: Codable, Identifiable { let type: String @@ -13,7 +43,10 @@ struct LibraryConflict: Codable, Identifiable { let fix_data: [String: AnyCodable]? var id: String { "\(type)|\(title)" } +} +// SwiftUI display helpers — in an extension so the base struct has no SwiftUI dependency +extension LibraryConflict { var severityColor: Color { severity == "error" ? Color(red: 1, green: 0.176, blue: 0.333) : .yellow } @@ -42,35 +75,6 @@ struct ConflictsResponse: Codable { let issues: [LibraryConflict] } -// MARK: - AnyCodable -// Wraps heterogeneous values in the fix_data dictionary (String, Int, or [String]). - -struct AnyCodable: Codable { - let value: Any - - init(_ value: Any) { self.value = value } - - init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - if let v = try? container.decode([String].self) { value = v; return } - if let v = try? container.decode([String: String].self) { value = v; return } - if let v = try? container.decode(String.self) { value = v; return } - if let v = try? container.decode(Int.self) { value = v; return } - value = "" - } - - func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - switch value { - case let v as [String]: try container.encode(v) - case let v as [String: String]: try container.encode(v) - case let v as String: try container.encode(v) - case let v as Int: try container.encode(v) - default: try container.encode("") - } - } -} - // MARK: - Conflict Manager @MainActor