---
title: Bool
framework: swift
role: symbol
role_heading: Structure
path: swift/bool
---

# Bool

A value type whose instances are either true or false.

## Declaration

```swift
@frozen struct Bool
```

## Overview

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

- [==(_:_:)](swift/bool/==(_:_:).md)
- [!=(_:_:)](swift/bool/!=(_:_:).md)

### Transforming a Boolean

- [toggle()](swift/bool/toggle().md)
- [!(_:)](swift/bool/!(_:).md)
- [||(_:_:)](swift/bool/__(_:_:).md)
- [&&(_:_:)](swift/bool/&&(_:_:).md)

### Creating a Random Value

- [random()](swift/bool/random().md)
- [random(using:)](swift/bool/random(using:).md)

### Describing a Boolean

- [description](swift/bool/description.md)

### Inspecting a Boolean

- [customMirror](swift/bool/custommirror.md)
- [customPlaygroundQuickLook](swift/bool/customplaygroundquicklook.md)
- [hashValue](swift/bool/hashvalue.md)
- [hash(into:)](swift/bool/hash(into:).md)

### Creating a Boolean From Another Value

- [init(_:)](swift/bool/init(_:)-25sp9.md)
- [init(_:)](swift/bool/init(_:)-83vgw.md)

### Converting an NSNumber to a Boolean

- [init(_:)](swift/bool/init(_:)-3mody.md)
- [init(exactly:)](swift/bool/init(exactly:).md)
- [init(truncating:)](swift/bool/init(truncating:).md)

### Encoding and Decoding

- [init(from:)](swift/bool/init(from:).md)
- [encode(to:)](swift/bool/encode(to:).md)

### Infrequently Used Intializers

- [init()](swift/bool/init().md)
- [init(booleanLiteral:)](swift/bool/init(booleanliteral:).md)

### Boolean Literals

- [true](swift/true.md)
- [false](swift/false.md)

### Structures

- [Bool.IntentDisplayName](swift/bool/intentdisplayname.md)

### Type Aliases

- [Bool.Specification](swift/bool/specification.md)
- [Bool.UnwrappedType](swift/bool/unwrappedtype.md)
- [Bool.ValueType](swift/bool/valuetype.md)

### Type Properties

- [defaultResolverSpecification](swift/bool/defaultresolverspecification.md)

### Default Implementations

- [AtomicRepresentable Implementations](swift/bool/atomicrepresentable-implementations.md)
- [CustomReflectable Implementations](swift/bool/customreflectable-implementations.md)
- [CustomStringConvertible Implementations](swift/bool/customstringconvertible-implementations.md)
- [Decodable Implementations](swift/bool/decodable-implementations.md)
- [Encodable Implementations](swift/bool/encodable-implementations.md)
- [Equatable Implementations](swift/bool/equatable-implementations.md)
- [ExpressibleByBooleanLiteral Implementations](swift/bool/expressiblebybooleanliteral-implementations.md)
- [Hashable Implementations](swift/bool/hashable-implementations.md)
- [LosslessStringConvertible Implementations](swift/bool/losslessstringconvertible-implementations.md)

## Relationships

### Conforms To

- [AtomicRepresentable](synchronization/atomicrepresentable.md)
- [BNNSScalar](accelerate/bnnsscalar.md)
- [BindableData](realitykit/bindabledata.md)
- [BitwiseCopyable](swift/bitwisecopyable.md)
- [CKRecordValueProtocol](cloudkit/ckrecordvalueprotocol.md)
- [CVAttachmentValueRepresentable](corevideo/cvattachmentvaluerepresentable.md)
- [CVarArg](swift/cvararg.md)
- [ConvertibleFromGeneratedContent](foundationmodels/convertiblefromgeneratedcontent.md)
- [ConvertibleToGeneratedContent](foundationmodels/convertibletogeneratedcontent.md)
- [Copyable](swift/copyable.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [ExpressibleByBooleanLiteral](swift/expressiblebybooleanliteral.md)
- [Generable](foundationmodels/generable.md)
- [Hashable](swift/hashable.md)
- [InstructionsRepresentable](foundationmodels/instructionsrepresentable.md)
- [IntentValueConvertible](appintents/intentvalueconvertible.md)
- [IntentValueExpressing](appintents/intentvalueexpressing.md)
- [LosslessStringConvertible](swift/losslessstringconvertible.md)
- [MLDataValueConvertible](createml/mldatavalueconvertible.md)
- [MLTensorScalar](coreml/mltensorscalar.md)
- [MusicLibraryRequestFilterValueEquatable](musickit/musiclibraryrequestfiltervalueequatable.md)
- [PromptRepresentable](foundationmodels/promptrepresentable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [USDPrim.Attribute.MetadataValue](usdkit/usdprim/attribute/metadatavalue.md)
- [USDPrim.Attribute.Value](usdkit/usdprim/attribute/value.md)
- [USDValueProtocol](usdkit/usdvalueprotocol.md)
