-1

I'm Learning swift using playgrounds. Can I declare a bool and have it be only true or false so I can use it as a condition for a function?

  • 4
    Swift has a `Bool` type, and `let b = true` defines a value of that type. I don't want to sound rude, but I would suggest to read "A Swift Tour" in the Swift reference which is available as eBook and at https://developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/index.html. – Or did I misunderstand your question? – Martin R Oct 02 '16 at 16:44

2 Answers2

1

Simply writing:

var boolean = true

will create a boolean named 'boolean' and will be equal to true. You can change it's value to false by writing

boolean = false 

later on. The boolean variable will be true or false, not at the same time. I don't wanna be rude but you should check simple variable types and learn from there. It's easier that way.

Atakan Cavuslu
  • 914
  • 1
  • 9
  • 17
0
You can declare a Boolean variable using "Bool" type annotation .  For  Example      
var boolean = false 
or 
var boolean =  Bool()

if you want to use in an if else condition . you can do like that

if boolean == true {

// Statements

}

Here , boolean is variable name .You can take any variable name.
Harish Singh
  • 765
  • 1
  • 12
  • 23