---
title: "bool(forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/userdefaults/bool(forkey:)"
---

# bool(forKey:)

Returns the Boolean value associated with the specified key.

## Declaration

```swift
func bool(forKey defaultName: String) -> Bool
```

## Parameters

- `defaultName`: The key to retrieve from the defaults database.

## Return Value

Return Value The Boolean value associated with defaultName, or false if the key isn’t present in the defaults database.

## Discussion

Discussion This method automatically coerces certain values to their equivalent Boolean meanings. For example, it coerces the numbers 1 and 1.0, and the strings “true”, “YES”, and “1” to the value true.

## See Also

### Getting the value of a key

- [integer(forKey:)](foundation/userdefaults/integer(forkey:).md)
- [float(forKey:)](foundation/userdefaults/float(forkey:).md)
- [double(forKey:)](foundation/userdefaults/double(forkey:).md)
- [url(forKey:)](foundation/userdefaults/url(forkey:).md)
- [string(forKey:)](foundation/userdefaults/string(forkey:).md)
- [stringArray(forKey:)](foundation/userdefaults/stringarray(forkey:).md)
- [data(forKey:)](foundation/userdefaults/data(forkey:).md)
- [object(forKey:)](foundation/userdefaults/object(forkey:).md)
- [array(forKey:)](foundation/userdefaults/array(forkey:).md)
- [dictionary(forKey:)](foundation/userdefaults/dictionary(forkey:).md)
- [dictionaryRepresentation()](foundation/userdefaults/dictionaryrepresentation().md)
