Is my Array Empty or not?

Today, I would like to show you how to check if an array is empty or not.

import UIKit

var TestArray = ["House","Mouse","Spouse"]  // Create an Array with 3 Strings

TestArray.removeAll() // Remove all Strings from the array

if TestArray.isEmpty {
print("Array is empty")// If Array is empty, print "Array is empty"
} else {
print("Array is not empty")// If Array is not empty, print "Array is not empty"
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s