.isEmpty
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"] = 12print(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:
truefalse