IBDecodable icon indicating copy to clipboard operation
IBDecodable copied to clipboard

How to manage non-optional value: Make all properties of models optional ?

Open phimage opened this issue 7 years ago • 4 comments

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

phimage avatar Apr 21 '18 17:04 phimage

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

phimage avatar Apr 21 '18 17:04 phimage

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.

phimage avatar Apr 21 '18 17:04 phimage

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

phimage avatar May 09 '18 06:05 phimage

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

SD10 avatar May 09 '18 12:05 SD10