NEW: Master Swift design patterns with my latest book! >>

< Previous: Range operators   Next: For loops >

Operators and conditions summary

You’ve made it to the end of the third part of this series, so let’s summarize:

  1. Swift has operators for doing arithmetic and for comparison; they mostly work like you already know.
  2. There are compound variants of arithmetic operators that modify their variables in place: +=, -=, and so on.
  3. You can use if, else, and else if to run code based on the result of a condition.
  4. Swift has a ternary operator that combines a check with true and false code blocks. Although you might see it in other code, I wouldn’t recommend using it yourself.
  5. If you have multiple conditions using the same value, it’s often clearer to use switch instead.
  6. You can make ranges using ..< and ... depending on whether the last number should be excluded or included.

Want to build macOS apps?

Hacking with macOS delivers 18 awesome projects that teach you macOS development in no time – take control of your desktop today!

< Previous: Range operators   Next: For loops >
Click here to visit the Hacking with Swift store >>