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 has been archived by the owner on Mar 10, 2022. It is now read-only.
The basic idea is that on the model level, you can mark one or more properties to be required so if in the incoming raw response they are not present stop the decoding and return empty struct/dictionary.
The text was updated successfully, but these errors were encountered:
I was thinking a bit about how we could do this and the only way I can think of is defining new operators/functions that take a new parameter - an option set specifying the required state (or other options) of a given property. That enum could look something like this:
struct PropertyOptions: OptionSet {
let rawValue: Int
static let required = PropertyOptions(rawValue: 1 << 0)
}
So for example, this would change:
title <== (self, dictionary, "title")
to this:
title <== (self, dictionary, "title", [.required])
for a property that would need to be required. Ideally this thing would be optional, so that we maintain backwards compatibility and also make the code less cluttered and easier to read.
And as for how we would handle this internally - I am not a big fan of failable or throwing initializers for models, but it would have to be one of these options. I'm open to any suggestions, as I haven't yet made up my mind about what would be a better option. :D
The basic idea is that on the model level, you can mark one or more properties to be required so if in the incoming raw response they are not present stop the decoding and return empty struct/dictionary.
The text was updated successfully, but these errors were encountered: