.isEmpty

Published Oct 11, 2022
Contribute to Docs

The .isEmpty property will return a true value if there are no key-value pairs in a dictionary and false if the dictionary does contain key-value pairs.

Syntax

dictionaryInstance.isEmpty

Example

var bakery = [String:Int]()
print(bakery.isEmpty)
bakery["Cupcakes"] = 12
print(bakery.isEmpty)

In the example above, the bakery dictionary is checked if it .isEmpty; once when it is initiated, and again when a key-value pair is added. This will output:

true
false

All contributors

Looking to contribute?

Learn Swift on Codecademy