The isEmpty
property of a Dictionary instance allows us to see whether a dictionary is empty or not. An empty dictionary contains no key-value pairs.
dictionary.isEmpty
This function does not take any parameters.
The value returned is a Boolean. If it is empty, a true
is returned, otherwise a false
is returned.
// create dictionariesvar dict1 : [String: String] = [:]var dict2 = ["name": "Theodore","role": "Developer"]// check if emptyprint(type(of : dict1), dict1.isEmpty)print(type(of : dict2), dict2.isEmpty)
dict1
and dict2
.