What type Bool or Int ?

swift

#1

Добрый день

Читая “The swift programming language” наткнулся на не понятный момент, в разделе “Booleans” (Логические типы), есть пример:

Пример

let i = 1
if i == 1 {
// this example will compile successfully
}

В книге пишется, что результат сравнения i == 1 имеет тип Bool, я на вожу курсор на i пишет что i имеет тип Int. Как это понять?

28

Цитата из книги

The result of the i == 1 comparison is of type Bool, and so this second example passes the type-check. Comparisons like i == 1 are discussed in Basic Operators.

As with other examples of type safety in Swift, this approach avoids accidental errors and ensures that the intention of a particular section of code is always clear.

Буду очень признателен если, кто сможет объяснить.


#2

Имеется ввиду что сравнение
if i == 1 { }
возвращает true
так как при условии
if i == 2 { }
вернется false
То есть i это Int а результат сравнение это Bool


#3

Спасибо добрый человек, теперь разобрался

let i = 1
if i == 1 {
print(“true”)
} else {
print(“false”)
}