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