O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic operators

Swift provides the following basic operations:

  • The = operator for assignments, similar to many different programming languages.
  • The + operator for addition, - for subtraction, * for multiplication, / for division, and % for remainders. These operators are functions that can be passed to other functions.
  • The -i operator for unary minus and +i for unary plus operations.
  • The +=, -=, and *= operators for compound assignments.
  • The a == b operator for equality, a != b for inequality, and a>b, a<b, and a<=b for greatness comparison.
  • The ternary conditional operator, question ? answer1: answer2.
  • nil coalescing a ?? b unwraps optional a if it has a value and returns a default value b if a is nil.
  • Range operators:
    • Closed range (

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required