Skip to content

Commit

Permalink
Make decode public
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Rydenstam committed May 24, 2023
1 parent 3089636 commit 570b05f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/OptionallyDecodable/OptionallyDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension OptionallyDecodable: Decodable {
}

/// We need this protocol to circumvent how the Swift compiler currently handles non-existing fields for property wrappers, always failing when there is no matching key.
protocol NullableCodable {
public protocol NullableCodable {
associatedtype Wrapped: Decodable, ExpressibleByNilLiteral
var wrappedValue: Wrapped { get }
init(wrappedValue: Wrapped)
Expand All @@ -32,7 +32,7 @@ extension OptionallyDecodable: NullableCodable {}

extension KeyedDecodingContainer {
/// Necessary for handling non-existing fields, due to how Swift compiler currently synthesises decoders for property wrappers, always failing when there is no matching key.
func decode<T: NullableCodable>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
public func decode<T: NullableCodable>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
let decoded = try self.decodeIfPresent(T.self, forKey: key) ?? T(wrappedValue: nil)
return decoded
}
Expand Down

0 comments on commit 570b05f

Please sign in to comment.