How to declare Array in swift language iOS

How to Create Array in swift language 

The array is used for store multiple values. Array available any type of language.The array is store only values and array is accessed by id.Id is stat by 0,1,2,3,4...

The array is two way to create .first way is an empty array and second array with an array literal.you are store multiple values.The array is most importation for the store .The array is very flexible. you can append array, remove array,  insert array etc.   watch  this video for more understanding.


Download     


empty array
var friend:Array = [String] ()

Creating an Array with an Array Literal
var myFriendArray:Array = ["parth","hardik","fevin","hiren"]

access array values by 0,1,2,3..

  myFriendArray[0]       

change values in the array

   myFriendArray[3] = "vijay"     

append array

myFriendArray.append("king")   

insert value in fixed id

myFriendArray.insert("sarag", atIndex: 2)

removeFirst() function only removes first value of array

myFriendArray.removeFirst()    

removeLast() function is remove last value of array

myFriendArray.removeLast()     

removeAtIndex() function is remove id 2 value of array

myFriendArray.removeAtIndex(2)

the reverse function is used to print the reverse value of the array

myFriendArray = myFriendArray.reverse()   

count a value in the array

myFriendArray.count   

remove all values

myFriendArray.removeAll()     

remove all values 

myFriendArray.removeAll(keepCapacity: false



if you are more understanding  about variable open this line 



No comments :

No comments :

Post a Comment