3 ms·
If you're talking about either the bad (pyramid of doom) code in Myth #1 - or the good code there, then it is indeed protecting against null values in the JSON.
by jtbrown 11y ago
If you're talking about either the bad (pyramid of doom) code in Myth #1 - or the good code there, then it is indeed protecting against null values in the JSON. When you try to cast with `as? String`, it returns nil when there's a null value in the JSON and the code in the `if` block is skipped (and the `else` block is executed if one exists).
- seanalltogether 11y agoThe point is that neither of them are good. Nulls should be expected in json objects, so why write the parsing inside a conditional that will fail when one is encountered?