Skip to content

Instantly share code, notes, and snippets.

@stleamist
Last active June 17, 2020 03:36
Show Gist options
  • Save stleamist/2dac370c6c778adda116efa0df72958b to your computer and use it in GitHub Desktop.
Save stleamist/2dac370c6c778adda116efa0df72958b to your computer and use it in GitHub Desktop.
import Foundation
@propertyWrapper
public struct NullableURL: Codable {
public let wrappedValue: URL?
public init(wrappedValue: URL?) {
self.wrappedValue = wrappedValue
}
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.wrappedValue = try? container.decode(URL?.self)
}
public func encode(to encoder: Encoder) throws {
try wrappedValue.encode(to: encoder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment