Back to blog

The Swift 5 Cheatsheet (Updated!)

Aasif Khan
By Aasif Khan | Last Updated on March 13th, 2024 6:42 am

Why learn by heart if you can cheat? Grab my open source cheatsheet for Swift 5, including common syntax for functions, variables, collections, Object-Oriented Programming, closures, generics, error handling and more!

In This Cheatsheet

Compared to the previous versions of the cheatsheet, a lot has changed. It’s expanded, made clearer, upgraded and updated. I’ve added explanations alongside the code examples to help beginner iOS developers get to grips with Swift from a birds-eye view.

This cheatsheet includes:

  • Variables, including primitives and common variable types
  • Functions, including function declaration and usage
  • Operators, from logical operators to ranges to math – it’s in here
  • Classes, including class declaration, protocols, outlets, properties, initializers, extensions, lazy properties and class methods
  • Instances, including initialization and using properties
  • Control Flow, including if-else if-else statements and switch
  • Loops, including for, while and Swift range syntax
  • Conditionals, including expressions, boolean logic and operators
  • Strings, including working with strings, converting from String to Int, and string interpolation
  • Optionals, including optional binding, optional chaining and force unwrapping
  • Dictionaries, including initialization and accessing key-value pairs
  • Arrays, including accessing values, adding values and looping over values
  • Sets, including what makes them special compared to dictionaries and arrays
  • Closures, including complete closure syntax, capturing and escaping
  • Guard & Defer, including early return with guard and deferred execution with defer
  • Generics, including generic types and function generics
  • Tuples, because while I’m at it I might as well add tuple syntax too…
  • Enumerations, including raw values, associated values and using enums with switch
  • Error Handling, including throwing errors and catching them with do-try-catch

The Swift Cheatsheet Is Open Source

Good things happen when you work together! My Swift 5 cheatsheet is open source. This means you can do with it whatever you want, as long as you keep the open source license intact.

The most successful people I know share their work. As you’re learning how to code iOS apps, making this your practice is essential.

Can you help? Contribute your Swift code examples, tidbits and cheats by creating a Pull Request (PR) on GitHub. If you have an idea or found a bug, please share it by creating an Issue ticket.

And of course – help your fellow coder to cheat by passing along this Swift cheatsheet!

Try Out Your Code In The Swift Sandbox

Don’t got Xcode or Playgrounds handy? Try your favorite Swift tricks with the handy Swift sandbox below. It couldn’t be simpler: just type in your code and click “Run”.
let greeting = “Hello world!”

for _ in 1…5 {

Further Reading

Save the whales, the trees and the arctic, and don’t print out this cheatsheet! Simply save the PDF and keep it open while you’re coding.

Aasif Khan

Head of SEO at Appy Pie

App Builder

Most Popular Posts