Closed danielgarbien closed 8 years ago
This is great!
Nice! Could you just add a short comment describing the .UnexpectedValue
so it's not confused in any way with .TypeMismatch
?
(Was bit uncomfortable by having the .UnexpectedValue
inside DecodingError
, but then realized that it has to for the DecodingError.Info
-things to work, so sure. I should perhaps rethink the error handling tough)
And a minor detail, but how about this instead?
public extension RawRepresentable where RawValue: Decodable, Self: Decodable {
static func decode(json: AnyObject) throws -> Self {
let rawValue = try RawValue.decode(json)
guard let rawRepresentable = Self(rawValue: rawValue) else {
throw DecodingError.UnexpectedValue(value: rawValue as! AnyObject, info: DecodingError.Info(object: json))
}
return rawRepresentable
}
}
Sure, it now fits better the implementation of extensions on arrays and dictionaries.
Thank you very much!
…entation.