Swift Cheat Sheet
An index refers to an item’s position within an ordered list. Use the subscript syntax, arrayindex, to retrieve an individual element from an array. Note: Swift arrays are zero-indexed, meaning the first element has index 0. Swift is more than 2.6x faster than Objective-C and more than 8.4x faster than Python. Swift 1.0 was released in September 2014. This article is also available as a download, Cheat sheet: Apple's. Swift is more than 2.6x faster than Objective-C and more than 8.4x faster than Python. Swift 1.0 was released in September 2014. This article is also available as a download, Cheat sheet: Apple’s Swift programming language (free PDF). SEE: 10 ways to prevent developer burnout (free PDF) (TechRepublic). Swift supports arithmetic operators for: + addition-subtraction. multiplication / division% remainder; var x = 0 x = 4 + 2 // x is now 6 x = 4 - 2 // x is now 2 x = 4. 2 // x is now 8 x = 4 / 2 // x is now 2 x = 4% 2 // x is now 0. Type annotation can be used during declaration. Swift Cheat Sheet. A quick cheat sheet and reference guide for Apple's Swift language. This guide intends to cover all the key features of Swift, including Strings, Arrays, Dictionaries and Flow Control. Swift is a new programming language for developing iOS and OS X apps that was introduced by Apple in June 2014.
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-elseif-else
statements andswitch
- Loops, including
for
,while
and Swift range syntax - Conditionals, including expressions, boolean logic and operators
- Strings, including working with strings, converting from
String
toInt
, 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 withdefer
- 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”.
for _ in 1...5 {
print(greeting)
}
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.
Want to learn more? Check out these resources:
by Chris Ching
If you’ve ever tried to learn Swift, you’ll know that there are tons of outdated resources floating around the internet because Swift is in its infancy and Apple updates the language so often.
It’s a tremendous effort, but I’ve kept the following tutorials up to date and will continue to do so!
With that said, let’s dive into the lessons!
Psst! Download and print out my trusty Swift Syntax Cheat Sheet.
Table of Contents

1. Variables
In this lesson, you’ll start at the very beginning with variables.
2. Data Types
This lesson will show you some of the common data types you work with when building apps.
3. If Statements
Learn how to write code that can make decisions!
4. Switch Statements
Switch statements are another way for your code to make decisions.
5. Loops
Sometimes you just need to repeat something. Loops are just for that!
6. Loops Part 2
More on loops…
7. Functions
In this lesson, you’ll learn how to organize your code into actionable functions.
8. Functions Part 2
There’s a lot to functions! This lesson goes into more depth.
9. Classes
Classes are another way to organize your code. This lesson is a must!
10. Classes Part 2 – Inheritance
More on classes…
11. UIKit
The UIKit framework provides a lot of reusable code for us!
12. Initializers
Initializers are important to understand along with classes.
13. Optionals
In this lesson, you’ll learn what an optional is.
14. Properties
Properties are kind of like variables but in the context of a class.
15. Initializers Part 2
More on initializers…
16. Arrays
You’re starting to learn about collection types now! Arrays are first.
17. Dictionaries
Dictionaries are another collection type.
Want to test what you’ve learned? Take a crack at the challenges below!
You may have to review some of the lessons to refresh your memory but I guarantee that completing these challenges will reinforce what you’ve learned in the lessons above.

When you complete all of the challenges, get your name on the Wall of Fame in the next section!
Instructions
In this challenge, you’ll write a function that searches two arrays to find an animal.
In this challenge, you’ll implement the missing function code to make this caterpillar go!
In the toughest challenge of this series yet, you’ll complete the class definition to enable searching for books, checking in/out books and also checking for errors too!
Solutions
Get your name and Twitter profile mentioned here!
Step 1: Complete the challenges in the Challenges section above.
Step 2: Click the card below to send out the tweet! I’ll see your tweet and I’ll add your name below and a link to your Twitter profile.
I completed all the Learn Swift challenges! Try them here: https://codewithchris.com/learn-swift @CodeWithChrisClick To TweetSwift Cheat Sheet 2019 Pdf
After you complete the challenges, Click to Tweet above and pronounce your victory! I’ll add your name below:
