How to check if an array is empty in Swift

How to check if an array is empty in Swift

In this post we will give you information about How to check if an array is empty in Swift. Hear we will give you detail about How to check if an array is empty in SwiftAnd how to use it also give you demo for it if it is necessary.

we are going to learn about how to check if the array is empty or not in Swift.

Checking array is empty

To check if a array is empty or not, we can use the built-in isEmpty property in Swift.

The isEmpty instance property returns true if an array is empty; otherwise returns false.

Here is an example:

var names:[String] = []print(names.isEmpty)

Output:

true

or we can also check it like this:

var names:[String] = []if(names.count == 0){    print("names array is empty")}else{    print("names array is not empty")}

Output:

"names array is empty"

Hope this code and post will helped you for implement How to check if an array is empty in Swift. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US