O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

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

Chapter    18

Logical Operators

The logical operators are used with boolean values and expressions that return boolean values. You use these operators to deal with expressions that are made up of parts that can be either true or false. Logical operators are used to test whether two expressions are true or whether one expression is true. Table 18-1 describes the logical operators supported by Swift.

Table 18-1. Logical Operators

Operator

Description

!x

Logical NOT

x && y

Logical AND

x || y

Logical OR

For instance, let’s assume you already have two variables, x and y, with values of true and false. To test and see whether both x and y are true, you would use logical AND, as shown in Listing 18-1.

Listing 18-1. Logical AND

let x = truelet y = ...

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