Open markst opened 7 years ago
Hmm, I see the problem. I don't know whether unformatting to optionals is the best solution though. I think optionals are only there to support null values, in which case the server response for the attribute should be "null" in the first place. I think it would be better to solve this in the unformatting itself. E.g. returning some fallback value, or throwing a warning.
I don't know the context of this case of course, but it seems to me that the response should actually be "null" for the profile-image-url attribute.
I feel like value formatter return value should be optional.
For example I have a mapping attribute such as:
"profilePhotoURL": URLAttribute().serializeAs("profile-image-url")
& my response is an empty string for myprofile-image-url
.If
URL(string:)
fails due to empty string it is then forcefully unwrapped byURLValueFormatter
which causes an exception.