You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
👋 I was wondering if there was interest in me adding a default decode function for RawRepresentable types?
An example of what I'm using in my own project:
func decode<T:RawRepresentable>(_ dictionary:JSONDictionary, key:String)throws->T{letobject:Any=trydecode(dictionary, key: key)guardlet rawValue = object as?T.RawValueelse{throwJSONDeserializationError.invalidAttributeType(key: key, expectedType:T.self, receivedValue: object)}guardlet value =T(rawValue: rawValue)else{
// Ideally represented by a new error case called `.invalidRawValue(key: key, rawValue: rawValue)`
throwJSONDeserializationError.invalidAttribute(key: key)}return value
}
If there's interest, I can add the code, add a specific error case, update the readme, and add tests 😄 .
Regardless, thanks for the project. It's been a pleasure to work with.