Skip to content

Instantly share code, notes, and snippets.

@nisshiee
Created February 12, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisshiee/d4833ef255c25e2a04113b1400629e6c to your computer and use it in GitHub Desktop.
Save nisshiee/d4833ef255c25e2a04113b1400629e6c to your computer and use it in GitHub Desktop.
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