Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Bool vs Boolean

Tags:

swift

boolean

I am teaching myself to program using Swift 3, and I am currently learning about booleans. I noticed that if I want to explicitly declare my variable of type bool, I have two options

Bool

or

Boolean

I was wondering why we have these two options if they are the same? Well, are they the same? This is what I'm confused about.

Thanks in advance.

like image 447
AmaCode Avatar asked Nov 24 '16 01:11

AmaCode


People also ask

What does bool mean in Swift?

Bool represents Boolean values in Swift. Create instances of Bool by using one of the Boolean literals true or false , or by assigning the result of a Boolean method or operation to a variable or constant.

How do you declare a boolean value in Swift?

Swift recognizes a value as boolean if it sees true or false . You can implicitly declar a boolean variable let a = false or explicitly declare a boolean variable let i:Bool = true .

What is default value for bool in Swift?

Bool in Swift is not a primitive. Everything in Swift are objects. Your variable test is a Bool! , which is an implicitly unwrapped optional and the default value is nil .

Is a bool?

In computer science, a boolean or bool is a data type with two possible values: true or false. It is named after the English mathematician and logician George Boole, whose algebraic and logical systems are used in all modern digital computers. Boolean is pronounced BOOL-ee-an.


1 Answers

Bool is Swift's boolean data type. Boolean hasn't existed since the early days of Swift.

like image 196
Alexander Avatar answered Oct 20 '22 09:10

Alexander