Chapter    7

Booleans

Boolean values can be either true or false. Booleans are used to help evaluate logical expressions. To declare a boolean value, you can assign a value immediately, or you can use the Bool data type to declare a boolean variable, as shown in Listing 7-1.

Listing 7-1. Declaring Booleans

var b1:Boollet b2 = false

In Chapter 6, you saw how to make a comparison between two strings to get a boolean value. You can store the results of an equality comparison like that in a boolean variable or constant, as shown in Listing 7-2.

Listing 7-2. Storing Boolean Results

let alphabet = "ABCDEFGHIJKLMNOP"let b4 = alphabet == "ABCDEFGHIJKLMNOP"

In Listing 7-2, the value of b4 is true because the two strings are the same; you can use this ...

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.