Followers

Sunday, 6 July 2014

Working with Array

An array stores multiple values of the same type in an ordered list. The same value can appear in an array multiple times at different positions.
Swift array types are implemented as structures. To understand their behaviour, lets start working on some of the examples,

Understanding, How copy works in an Array:














In the above example, its clear that if you assign array 'a' to 'b' they share the same elements.
Case 1: When you change the element at index[0], they still share the same elements.
Case 2: If you append any of the array 'a' or 'b', they refer to an independent set of array elements.

Ensuring that an array is Unique:















Calling unshare() on an array, ensures a unique copy of an array.

Checking whether two arrays are Unique: In other words, making a check if they share same elements or not
Initialising, appending an array 
Iterating through an array 
Removing items from an array
Pre-Populating an array with same values, Concatenation

No comments:

Post a Comment