Yes! Someone finally said it. The worst are the operators. You don't need these libraries and their lack of tests.
Noticed this might be an ad about a book... Parsing JSON in Swift. The bubble is real. What developer would buy this? What's next, a book about NSURLSession?
Swiftz (https://github.com/typelift/Swiftz) offers well tested implementation of operator definitions and constructs from functional language. It takes inspiration from Scalaz and Haskell.
If I were to write a library using wacky operators, I'd at least use well defined and maintained definitions.
How sad. Apple has 80 billion dollar in cash - and are unable to pay someone to write a standard JSON parser - for a language they want other developer to adopt. Do they expect unpaid developers to make one for them ?
And here's your regularly scheduled announcement that the actual JSON parsing is done by the library call NSJSONSerialization.JSONObjectWithData(...) in line 3 of the code.
The rest is just getting the parsed data out of already parsed nested dictionaries and arrays in a way that makes the type checker happy. Calling that "parsing" is probably the biggest myth of them all (though agreed about all the other myths).
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).
The 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?
14 comments
[ 3.0 ms ] story [ 12.3 ms ] threadNoticed this might be an ad about a book... Parsing JSON in Swift. The bubble is real. What developer would buy this? What's next, a book about NSURLSession?
I don't know why anyone would bother writing their own, though.
(IMA non-swift programmer)
The rest is just getting the parsed data out of already parsed nested dictionaries and arrays in a way that makes the type checker happy. Calling that "parsing" is probably the biggest myth of them all (though agreed about all the other myths).
What I'd really like is a way to write my POD types as normal:
And then just write this to parse it all. I'd be willing to accept having to annotate some of the fields, (but other than that, this should be possible to do).