iOS Development with Swift 2 - Arrays

Arrays are the data types that store the same type of data in an ordered list. The same value can appear at multiple indexes/Places in an array.

Operations on an Array

Swift provides multiple operations that we can apply on arrays according to the user Requirement. Some of the most commonly used ones are given below.

  • var ArrayName = [Datatype]() // Creates an empty Array of Datatype.

  • var newArray = [Int]() // Creates an empty Integer Array.

  • newArray = [1,2,3] // Assigns Three Values to the Array.

  • newArray.count // Prints the count of Array.

  • newArray.isEmpty // Checks if array is empty.

  • newArray.append(4) // Adds an element at the end of array.

  • var firstItem = newArray[0] // creates a variable with value of first element of newArray.

  • newArray.insert(7, at: 0) // inserts value 7 at 0th index of newArray

  • newArray.remove(at: 2) // removes value from 2nd index of newArray.

Kickstart Your Career

Get certified by completing the course

Get Started