Array in Swift

Define empty interger array

You can us isEmpty property to check whether the array is empty

Add element to array

You can insert element at specific index

This will add 10 at the index 0

Remove Elements

To remove element at specific location you can use remove()

Remove all elemnts

You can define array with elemnts

Iterating Array

To loop through the array you can use for loop

Output
Number is: 1
Number is: 2
Number is: 3
Number is: 4
Number is: 5
Number is: 6
Number is: 7
Number is: 8
Number is: 9

You can use this for loop to loop through the array

Another method

Define double array with 5 elements

Leave a Reply

Your email address will not be published. Required fields are marked *