Introducing the raywenderlich.com Swift Style Guide

Check out the first draft of our official Swift style guide – and submit your comments! By Ray Wenderlich.

Leave a rating/review
Save for later
Share

Contents

Hide contents

Ever since WWDC, we’ve been working very hard to create a ton of new Swift tutorials, video tutorials, and books.

But we realized pretty quickly – we needed a Swift style guide to keep our code organized and consistent!

So today, the team and I are very pleased to announce the first draft of the official raywenderlich.com Swift style guide!

Keep in mind Swift is still in beta and we’re still figuring a lot of things out, so consider this only the start. We’d appreciate your feedback and advice on where to take this next – feel free to submit issues or pull requests!

Note that this style guide is different than other style guides out there, in that its focus is on readability for printed books and the web. Many of the decisions were made with an eye toward conserving space for print, easy legibility, and tutorial writing.

So without further ado, check out the style guide or keep reading for the highlights of the guide, who worked on it, and how you can contribute!

Guide Highlights

Here are some of the highlights of the guide:

  • Avoid unnecessary code. In general, avoid using unnecessary (but optional) code in Swift. For example, don’t use self unless there’s a reason, avoid semicolons, prefer inferred typing.
  • Closure syntax. Use trailing closure syntax wherever possible, and prefer to use the closure parameters descriptive names.
  • Constants. Prefer to make your values constants with let – make variable with var only when necessary.
  • The Smiley Face. There is only one true smiley face :]

To learn more, check out the full Swift style guide.

Note we still have some unanswered questions and points of debate in the issues – we’d love to hear your thoughts!

How Was This Guide Developed?

This style guide was developed as a group effort from across the team.

Greg Heo served as the project manager for the style guide, and Colin Eberhardt (one of the co-authors of Swift by Tutorials) was an especially active committer.

In addition to those two, the style guide team members included Soheil Moayedi Azarpour, Scott Berrevoets, Eric Cerney, Sam Davies, Evan Dekhayser, Jean-Pierre Distler, Matthijs Hollemans, Erik Kerber, Christopher LaPollo, Andy Pereira, Ryan Nystrom, Cesare Rocchi, Ellen Shapiro, Marin Todorov, Chris Wagner, Ray Wenderlich, and Jack Wu.

How We’ll Use This Guide

We will strongly recommend tutorial authors on our site use this style guide moving forward. However, note that not every tutorial will be 100% compliant to the style guide – it’s asking a bit much for authors and editors to do that for free tutorials.

However, we will enforce the style guide rules in books and starter kits, as we always aim for a higher bar with those.

Comments on the Guide?

As we learned from developing this guide, there are always going to be strong opinions on code style issues.

And we’d love to hear yours! Do you love/hate any decisions we’ve made in the style guide? Post comments on this thread or file GitHub pull requests – I’ll be watching for them, and if you can convince me (and the rest of the team), we’ll change the guide.

We hope you enjoy our Swift style guide – and stay tuned for some more consistent tutorials and books! :]

Contributors

Over 300 content creators. Join our team.