Created
February 12, 2021 13:55
-
-
Save nisshiee/d4833ef255c25e2a04113b1400629e6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Apollo | |
public struct KCal: JSONDecodable, JSONEncodable { | |
let value: Double | |
public init(jsonValue value: Apollo.JSONValue) throws { | |
guard let value = value as? Double else { throw JSONDecodingError.wrongType } | |
guard (value.isZero || value.isNormal) && value >= 0.0 else { throw JSONDecodingError.couldNotConvert(value: value, to: KCal.self) } | |
self.value = value | |
} | |
public var jsonValue: JSONValue { | |
return self.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment