.isEmpty
Anonymous contributor
Published Sep 25, 2023
Contribute to Docs
The .isEmpty
property returns true
if an array contains no elements, and returns false
if the array contains one or more elements.
Syntax
arrayName.isEmpty
Where arrayName
is the array being checked for elements.
Example
The following example creates and array and evaluates the contents of the array with .isEmpty
before and after adding an element:
var favoriteSongs = [String]()print(favoriteSongs.isEmpty)favoriteSongs.append("Stayin' Alive")print(favoriteSongs.isEmpty)
This will output:
truefalse
Note: Big-O of this method is O(1).
All contributors
- Anonymous contributor
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