Skip to content

Commit

Permalink
feat: add decoding nullable array property wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Jul 28, 2024
1 parent 8d33a2a commit f2b96fa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/VRCKit/Utils/NullableArray.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NullableArray.swift
//
//
// Created by makinosp on 2024/07/28.
//

import Foundation

@propertyWrapper
struct NullableArray<T: Decodable>: Decodable {
var wrappedValue: [T]

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if container.decodeNil() {
self.wrappedValue = []
} else {
self.wrappedValue = try container.decode([T].self)
}
}
}

0 comments on commit f2b96fa

Please sign in to comment.