<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Bool",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sb"
  },
  "title" : "Bool"
}
-->

# Bool

A value type whose instances are either `true` or `false`.

```
@frozen struct Bool
```

## Overview

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

```
var godotHasArrived = false

let numbers = 1...5
let containsTen = numbers.contains(10)
print(containsTen)
// Prints "false"

let (a, b) = (100, 101)
let aFirst = a < b
print(aFirst)
// Prints "true"
```

Swift uses only simple Boolean values in conditional contexts to help avoid
accidental programming errors and to help maintain the clarity of each
control statement. Unlike in other programming languages, in Swift, integers
and strings cannot be used where a Boolean value is required.

For example, the following code sample does not compile, because it
attempts to use the integer `i` in a logical context:

```
var i = 5
while i {
    print(i)
    i -= 1
}
// error: Cannot convert value of type 'Int' to expected condition type 'Bool'
```

The correct approach in Swift is to compare the `i` value with zero in the
`while` statement.

```
while i != 0 {
    print(i)
    i -= 1
}
```

# Using Imported Boolean values

The C `bool` and `Boolean` types and the Objective-C `BOOL` type are all
bridged into Swift as `Bool`. The single `Bool` type in Swift guarantees
that functions, methods, and properties imported from C and Objective-C
have a consistent type interface.

## Topics

### Comparing Boolean Values

[`==(_:_:)`](/documentation/Swift/Bool/==(_:_:))

Returns a Boolean value indicating whether two values are equal.

[`!=(_:_:)`](/documentation/Swift/Bool/!=(_:_:))

Returns a Boolean value indicating whether two values are not equal.

### Transforming a Boolean

[`toggle()`](/documentation/Swift/Bool/toggle())

Toggles the Boolean variable’s value.

[`!(_:)`](/documentation/Swift/Bool/!(_:))

Performs a logical NOT operation on a Boolean value.

[`||(_:_:)`](/documentation/Swift/Bool/__(_:_:))

Performs a logical OR operation on two Boolean values.

[`&&(_:_:)`](/documentation/Swift/Bool/&&(_:_:))

Performs a logical AND operation on two Boolean values.

### Creating a Random Value

[`random()`](/documentation/Swift/Bool/random())

Returns a random Boolean value.

[`random(using:)`](/documentation/Swift/Bool/random(using:))

Returns a random Boolean value, using the given generator as a source for
randomness.

### Describing a Boolean

[`description`](/documentation/Swift/Bool/description)

A textual representation of the Boolean value.

### Inspecting a Boolean

[`customMirror`](/documentation/Swift/Bool/customMirror)

A mirror that reflects the `Bool` instance.

[`customPlaygroundQuickLook`](/documentation/Swift/Bool/customPlaygroundQuickLook)

A custom playground Quick Look for the `Bool` instance.

[`hashValue`](/documentation/Swift/Bool/hashValue)

The hash value.

[`hash(into:)`](/documentation/Swift/Bool/hash(into:))

Hashes the essential components of this value by feeding them into the
given hasher.

### Creating a Boolean From Another Value

[`init(_:)`](/documentation/Swift/Bool/init(_:)-25sp9)

Creates an instance equal to the given Boolean value.

[`init(_:)`](/documentation/Swift/Bool/init(_:)-83vgw)

Creates a new Boolean value from the given string.

### Converting an NSNumber to a Boolean

[`init(_:)`](/documentation/Swift/Bool/init(_:)-3mody)

[`init(exactly:)`](/documentation/Swift/Bool/init(exactly:))

[`init(truncating:)`](/documentation/Swift/Bool/init(truncating:))

### Encoding and Decoding

[`init(from:)`](/documentation/Swift/Bool/init(from:))

Creates a new instance by decoding from the given decoder.

[`encode(to:)`](/documentation/Swift/Bool/encode(to:))

Encodes this value into the given encoder.

### Using a Boolean as a Data Value

### Infrequently Used Intializers

[`init()`](/documentation/Swift/Bool/init())

Creates an instance initialized to `false`.

[`init(booleanLiteral:)`](/documentation/Swift/Bool/init(booleanLiteral:))

Creates an instance initialized to the specified Boolean literal.

### Boolean Literals

[`true`](/documentation/Swift/true)

A true value.

[`false`](/documentation/Swift/false)

A false value.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)