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    15

Comparison Operators

You use comparison operators to compare two values. You can test for equality or whether one value is greater or less than another value.

Table 15-1 describes the comparison operators available in Swift.

Table 15-1. Comparison Operators

Operator

Description

x == y

Equal to

x != y

Not equal to

x > y

Greater than

x >=y

Greater than or equal to

x < y

Less than

x <= y

Less than or equal to

x === y

Two objects are equal

x !== y

Two objects are not equal

Note  The last two comparison operators in Table 15-1 (=== and !==) apply only to objects (see Chapter 32). Objects are also known as instances in Swift.

Comparison operators return a boolean result that you can store in a boolean variable or constant. See

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