O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Is the array empty?

To check whether an array is empty (does not contain any elements), we use the isEmpty property. This property will return true if the array is empty and false if it is not. The following example shows how to check whether an array is empty or not:

var arrayOne = [1,2]  
var arrayTwo = [Int]() 
arrayOne.isEmpty  //Returns false because the array is not empty  
arrayTwo.isEmpty  //Returns true because the array is empty 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required