To check if an array is empty in Swift, you can use the isEmpty
property.
In this example,
numbers
with some elements.isEmpty
property and store the result in the variable isEmpty
.let numbers = [1, 2, 3]
let isEmpty = numbers.isEmpty
print("Array is empty: \(isEmpty)")
Array is empty: false
In this example,
emptyArray
.isEmpty
property and store the result in the variable isEmpty
.let emptyArray: [Int] = []
let isEmpty = emptyArray.isEmpty
print("Array is empty: \(isEmpty)")
Array is empty: true
In this tutorial, we learned How to check if an Array is Empty in Swift language with well detailed examples.