diff --git a/Sources/ObjectUI/Data/Object.swift b/Sources/ObjectUI/Data/Object.swift index 4cf8808..6263762 100644 --- a/Sources/ObjectUI/Data/Object.swift +++ b/Sources/ObjectUI/Data/Object.swift @@ -230,3 +230,40 @@ private extension Object { return unwrappedValue } } + +extension Object: CustomStringConvertible { + public var description: String { + """ + Object { + \( + variables + .map { (key, value) in + guard let object = value as? Object else { + return "|\t* \(key): \(value) (\(type(of: value)))" + } + + let values = object.description.split(separator: "\n") + .dropFirst() + + if values.dropLast().isEmpty { + return "|\t* \(key): Object { }" + } + + return "|\t* \(key): Object {\n\(values.map { "|\t \($0)" }.joined(separator: "\n"))" + } + .joined(separator: "\n") + ) + } + """ + } +} + +extension Object: Hashable { + public static func == (lhs: Object, rhs: Object) -> Bool { + lhs.description == rhs.description + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(description) + } +}