.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"] = 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
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Swift on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours