diff --git a/Sources/VRCKit/Utils/NullableArray.swift b/Sources/VRCKit/Utils/NullableArray.swift deleted file mode 100644 index 37e2b5c..0000000 --- a/Sources/VRCKit/Utils/NullableArray.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// NullableArray.swift -// -// -// Created by makinosp on 2024/07/28. -// - -import Foundation - -@propertyWrapper -public struct NullableArray { - public let wrappedValue: [T] - public init(wrappedValue: [T]) { - self.wrappedValue = wrappedValue - } -} - -extension NullableArray: Codable { - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - if container.decodeNil() { - wrappedValue = [] - } else { - wrappedValue = try container.decode([T].self) - } - } -} - -extension NullableArray: Hashable { - public static func == (lhs: NullableArray, rhs: NullableArray) -> Bool { - lhs == rhs - } -} diff --git a/Sources/VRCKit/Utils/SafeDecodingArray.swift b/Sources/VRCKit/Utils/SafeDecodingArray.swift new file mode 100644 index 0000000..21e378e --- /dev/null +++ b/Sources/VRCKit/Utils/SafeDecodingArray.swift @@ -0,0 +1,25 @@ +// +// SafeDecodingArray.swift +// +// +// Created by makinosp on 2024/07/28. +// + +import Foundation + +public struct SafeDecodingArray { + public let elements: [Element] +} + +extension SafeDecodingArray: Codable { + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + elements = (try? container.decode([Element].self)) ?? [] + } +} + +extension SafeDecodingArray: Hashable { + public static func == (lhs: SafeDecodingArray, rhs: SafeDecodingArray) -> Bool { + lhs == rhs + } +}