Previously we explored how to use Swift’s amazing type system to simplify our JSON code. We came up with a solution that was concise, without building a complicated tree of JSON enums, using crazy operators, or getting deep into reflection. And we did it all in 100-some-odd lines of code.
Long has the holy war between emacs and vi been waged. I’ve used both, and I don’t
really care either way. However, OS X text fields everywhere come with secret
support for limited (and sometimes modified) Emacs keybindings. So, regardless
of your position in the great text editor wars you might as well learn a few keybindings
because you can use them anywhere you see a text field. Learning a
few basic keybindings will empower you as an iOS/Mac developer and as an OS X user.
Last time we talked about how we could simplify our JSON parsing with Swift 2 error handling and get rid of all the magic. Today we’re going to use the power of type inference to take our old
JSONObject struct from having 12 methods (or more, if you want to add methods for values like CGFloat, etc.) to only 4!
Since the beginning, JSON parsing has been a common pain point for many Swift developers. This is largely due to difficulties in dealing with a strict type system (which JSON does not have) and optionals, as well as a lack of a consistent error handling approach.
Swift 2.0 is causing a lot of well deserved excitement. Chris and the folks over at
apple have been doing an amazing job.
I have been loving Swift the past year and am really excited about all the new
features—and, of course, the open source announcement.