Skip to content

Commit e33b2b3

Browse files
committed
feat: modify nullable array to safe decoding array
1 parent 34d8d6b commit e33b2b3

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Sources/VRCKit/Utils/NullableArray.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// SafeDecodingArray.swift
3+
//
4+
//
5+
// Created by makinosp on 2024/07/28.
6+
//
7+
8+
import Foundation
9+
10+
public struct SafeDecodingArray<Element: Codable & Hashable> {
11+
public let elements: [Element]
12+
}
13+
14+
extension SafeDecodingArray: Codable {
15+
public init(from decoder: Decoder) throws {
16+
let container = try decoder.singleValueContainer()
17+
elements = (try? container.decode([Element].self)) ?? []
18+
}
19+
}
20+
21+
extension SafeDecodingArray: Hashable {
22+
public static func == (lhs: SafeDecodingArray<Element>, rhs: SafeDecodingArray<Element>) -> Bool {
23+
lhs == rhs
24+
}
25+
}

0 commit comments

Comments
 (0)