How to manage non-optional value: Make all properties of models optional ?
From @SD10 on March 12, 2018 21:14
Currently, if a non-optional value does not exist the XML decoding fails.
I think this is a drawback because it doesn't allow you to investigate the structural integrity of the XML. For example, you can't ever write rules that determine if a required key is missing. Maybe someone corrupted the XML through a merge conflict.
This is also a concern for Boolean properties. If the value doesn't exist, we don't want to assume it's false 🤔
Copied from original issue: IBDecodable/IBLinter#33
For boolean properties I make some dirty code to have trueas default value
clearsSelectionOnViewWillAppear: (try? xml.attributeValue(of: "clearsSelectionOnViewWillAppear")) ?? true
I think this issue could be moved to IBDecodable if we achieve this #38
From @SD10 on April 9, 2018 16:13
Yeah @phimage I wanted your advice on this one. I think making everything optional is the way to go. Let me know what you think.
The main issue is that if element could not be decoded and this element is in a list with some flatMap, then we couldn't see the element
I think that having a mandatory attribute missing could throw an error and nothing is decoded! (maybe a configuration boolean could be introduced) In IBLinter, the exception is catched and unique error is displayed as error (not warning) A lot of linter or builder could stop to build or lint at first error
A lot of linter or builder could stop to build or lint at first error
Yep, I totally agree. I think on Natalie everything is optional