The Swift 5 Cheatsheet (Updated!)
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 {
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.
Related Articles
- How To Create A Social Media App Like Facebook, Twitter Or Instagram With Appy Pie’s App Builder?
- How To Create An App Like eBay?
- Top 10 WordPress Integrations to Increase Productivity
- Birthday Card Art: 7 DIY Ideas for your Next Design
- How to market your brand through Snapchat? [A Marketing Guide]
- Get Started with SwiftUI for iOS
- What is Bankruptcy? – Steps to File for Bankruptcy
- डेमो
- Top 20 interview questions and answers in 2023 [A useful guide to interviews]
- How to Create an App Like CNN?
Most Popular Posts
- How to Create an Android App [A Guide to Creating Android Apps in 2024]
By Deepak Joshi | December 21, 2023
- How To: Pass Data Between View Controllers in Swift
By Abhinav Girdhar | October 19, 2023
- How to Download Music From Spotify?
By Samarpit Nasa | October 18, 2023
- Instagram Hashtags – A Complete Guide with Ideas
By Aasif Khan | October 17, 2023
- How to Watch the Star Wars Movies in Order: A Journey through the Galaxy Far, Far Away
By Samarpit Nasa | October 16, 2023