A blog about Swift and iOS tricks

Checking if the collection is not empty

A more convenient way to check collection emptiness in swift

extension Collection  { 
    var isNotEmpty: Bool{ !isEmpty }
}

// conventional way
if  !array.isEmpty { // do sth}

// more readable way
if  array.isNotEmpty { // do sth}