Skip to content

Instantly share code, notes, and snippets.

@Anatoli-Petrosyants
Created February 1, 2018 07:48
Show Gist options
  • Save Anatoli-Petrosyants/8a2b7052ef122cec28c523a2d534f53c to your computer and use it in GitHub Desktop.
Save Anatoli-Petrosyants/8a2b7052ef122cec28c523a2d534f53c to your computer and use it in GitHub Desktop.
import Foundation
// MARK: Encode/decode helpers
class JSONNull: Codable {
public init() {}
public required init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if !container.decodeNil() {
throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull"))
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encodeNil()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment