Skip to content

Commit

Permalink
feat: modify nullable array to safe decoding array
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Aug 2, 2024
1 parent 34d8d6b commit e33b2b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
33 changes: 0 additions & 33 deletions Sources/VRCKit/Utils/NullableArray.swift

This file was deleted.

25 changes: 25 additions & 0 deletions Sources/VRCKit/Utils/SafeDecodingArray.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SafeDecodingArray.swift
//
//
// Created by makinosp on 2024/07/28.
//

import Foundation

public struct SafeDecodingArray<Element: Codable & Hashable> {
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<Element>, rhs: SafeDecodingArray<Element>) -> Bool {
lhs == rhs
}
}

0 comments on commit e33b2b3

Please sign in to comment.