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

Get Swift Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.