How to parse JSON with Swift 4

How do you parse JSON with Swift 4? Maybe you’ve done it with Swift 3 before, and if you have, you’ll be pleased to know that it’s so much better in Swift 4. And guess what? Nobody even calls it parsing any more — it’s decoding now. Apple has some new classes and protocols we can use: JSONDecoder and Decodable …

What’s the best way to learn iOS development with Swift?

I hear this question so often that it’s time for another roundup of the best online courses, videos, in-person classes, and books for learning iOS development and Swift. If you’ve looked, you already know there are a ton to choose from. This is a curated list of the ones that are recommended the most, ordered from free to most expensive. …

How to write a singleton in Swift

I’m as opposed to singletons as anyone else in general due to the fact that they make testing harder, but sometimes, like when managing access to a local SQLite database, I want to make sure there’s only one instance of the class that purges old records from it. So a singleton seems to make sense. But how do we do …

inessential: On Fixing that NSNull Crasher in Overcast

I love this story from Brent Simmons about how he found and fixed a crashing bug in Overcast. It’s great to be able to see his thought process and learn from how he fixes crashes. Related: you should read his entire series on How Not to Crash. It’s from 2015, but it’s still relevant today.

How to install multiple versions of Xcode at the same time

Despite what you may have heard, it is possible to have multiple versions of Xcode installed at the same time without using any special tools or apps. You’ll just need to use xcode-select on the command line to switch between them whenever you go from, for example, Xcode 9 back to Xcode 8. Install the latest version of Xcode from …

How to review a pull request for an iOS app

(or “How to review a merge request” if you’re using GitLab like my team. I’ll use the term “pull request” here.) What should you look for as you’re reviewing a pull request? It’s important to review the code and verify the functionality so you can be sure the change does what it should and doesn’t introduce any new issues. 1. …

When do you use optional chaining vs. if let or guard?

Short answer: I use optional chaining when I don’t really care if the operation fails; otherwise, I use if let or guard. OK, so what does that look like in practice? Let’s look at an implementation of our favorite UITableViewDataSource method, tableView(_cellForRowAt:): func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: “cell”, for: indexPath) cell.textLabel?.text …

Notifications and Alerts are Disruptive

Supertop: The latest beta release of iOS introduces a new feature that allows developers to prompt users to rate their apps. The rating is selected and submitted without leaving the app. It is presented as an alert, using the standard system appearance. As they go on to say, these are annoying. I agree. iOS already has a feature for communicating …

Improving Swift Compile Times

Let’s face it: there’s a limit to how much fun you can have while you’re waiting for code to compile. (via xkcd.com/303/) At some point, enough is enough. Our team has had enough fun compiling Swift code over the past year that we’ve incorporated the following into our project so we can spend less time compiling and more time working. …

How to parse JSON with Swift 3

Why is it so hard to parse JSON in Swift? I can’t count the number of times I’ve seen or heard this question since Swift came out. So what’s the problem? Shouldn’t a real programming language make it super simple to work with JSON since everyone uses it everywhere? The issue is that we’re taking weakly-typed JSON data and transforming …