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    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 ...

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