<!--
{
  "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

[`static func == (Bool, Bool) -> Bool`](/documentation/Swift/Bool/==(_:_:))

Returns a Boolean value indicating whether two values are equal.

[`static func != (borrowing Self, borrowing Self) -> Bool`](/documentation/Swift/Bool/!=(_:_:))

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

### Transforming a Boolean

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

Toggles the Boolean variable’s value.

[`static func ! (Bool) -> Bool`](/documentation/Swift/Bool/!(_:))

Performs a logical NOT operation on a Boolean value.

[`static func || (Bool, @autoclosure () throws -> Bool) rethrows -> Bool`](/documentation/Swift/Bool/__(_:_:))

Performs a logical OR operation on two Boolean values.

[`static func && (Bool, @autoclosure () throws -> Bool) rethrows -> Bool`](/documentation/Swift/Bool/&&(_:_:))

Performs a logical AND operation on two Boolean values.

### Creating a Random Value

[`static func random() -> Bool`](/documentation/Swift/Bool/random())

Returns a random Boolean value.

[`static func random<T>(using: inout T) -> Bool`](/documentation/Swift/Bool/random(using:))

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

### Describing a Boolean

[`var description: String`](/documentation/Swift/Bool/description)

A textual representation of the Boolean value.

### Inspecting a Boolean

[`var customMirror: Mirror`](/documentation/Swift/Bool/customMirror)

A mirror that reflects the `Bool` instance.

[`var customPlaygroundQuickLook: _PlaygroundQuickLook`](/documentation/Swift/Bool/customPlaygroundQuickLook)

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

[`var hashValue: Int`](/documentation/Swift/Bool/hashValue)

The hash value.

[`func hash(into: inout Hasher)`](/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(Bool)`](/documentation/Swift/Bool/init(_:)-25sp9)

Creates an instance equal to the given Boolean value.

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

Creates a new Boolean value from the given string.

### Converting an NSNumber to a Boolean

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

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

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

### Encoding and Decoding

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

Creates a new instance by decoding from the given decoder.

[`func encode(to: any Encoder) throws`](/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: Bool)`](/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.

### Structures

[`struct IntentDisplayName`](/documentation/Swift/Bool/IntentDisplayName)

### Type Aliases

[`typealias Specification`](/documentation/Swift/Bool/Specification)

[`typealias UnwrappedType`](/documentation/Swift/Bool/UnwrappedType)

[`typealias ValueType`](/documentation/Swift/Bool/ValueType)

### Type Properties

[`static var defaultResolverSpecification: some ResolverSpecification`](/documentation/Swift/Bool/defaultResolverSpecification)

### Default Implementations

[AtomicRepresentable Implementations](/documentation/Swift/Bool/AtomicRepresentable-Implementations)

[CustomReflectable Implementations](/documentation/Swift/Bool/CustomReflectable-Implementations)

[CustomStringConvertible Implementations](/documentation/Swift/Bool/CustomStringConvertible-Implementations)

[Decodable Implementations](/documentation/Swift/Bool/Decodable-Implementations)

[Encodable Implementations](/documentation/Swift/Bool/Encodable-Implementations)

[Equatable Implementations](/documentation/Swift/Bool/Equatable-Implementations)

[ExpressibleByBooleanLiteral Implementations](/documentation/Swift/Bool/ExpressibleByBooleanLiteral-Implementations)

[Hashable Implementations](/documentation/Swift/Bool/Hashable-Implementations)

[LosslessStringConvertible Implementations](/documentation/Swift/Bool/LosslessStringConvertible-Implementations)

## Relationships

### Conforms To

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

[`BindableData`](/documentation/RealityKit/BindableData)

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

[`IntentValueConvertible`](/documentation/AppIntents/IntentValueConvertible)

[`MLDataValueConvertible`](/documentation/CreateML/MLDataValueConvertible)

[`MusicLibraryRequestFilterValueEquatable`](/documentation/MusicKit/MusicLibraryRequestFilterValueEquatable)

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

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

[`AtomicRepresentable`](/documentation/Synchronization/AtomicRepresentable)

[`InstructionsRepresentable`](/documentation/FoundationModels/InstructionsRepresentable)

[`Generable`](/documentation/FoundationModels/Generable)

[`MetadataValue`](/documentation/USDKit/USDStage/Object/MetadataValue)

[`ConvertibleFromGeneratedContent`](/documentation/FoundationModels/ConvertibleFromGeneratedContent)

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

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

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

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

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

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

[`CKRecordValueProtocol`](/documentation/CloudKit/CKRecordValueProtocol)

[`Value`](/documentation/USDKit/USDPrim/Attribute/Value)

[`PromptRepresentable`](/documentation/FoundationModels/PromptRepresentable)

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

[`CVAttachmentValueRepresentable`](/documentation/CoreVideo/CVAttachmentValueRepresentable)

[`ConvertibleToGeneratedContent`](/documentation/FoundationModels/ConvertibleToGeneratedContent)

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

[`USDValueProtocol`](/documentation/USDKit/USDValueProtocol)

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

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

[`IntentValueExpressing`](/documentation/AppIntents/IntentValueExpressing)

[`BNNSScalar`](/documentation/Accelerate/BNNSScalar)

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

[`MLTensorScalar`](/documentation/CoreML/MLTensorScalar)

---

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)