you can create an emty array of a certain type using initializer syntax:
var number = [Int] ()
Note that the type of the number variable is inferred to be Int[], because it is set to the output of an Int[] initializerthe example below create an array called shoppinglist to store String values:
var shoppinglist:[String] = ["Eggs","Milk"];
array has specified a value type of string it is only allowed to store string values here,the shoppinglist array is initialized with two string values ("eggs"and "milk"),
written within an array literal.use the add a new item to the end of an array by calling the array's append method:
number.append (5)
shoppinglist.append("Apple")
(+=)
number += [1,2,3,4]
shoppinglist += ["Bred"]
number [0] = "5"
shoppinglist[0] = "Eggs"
method:
number.insert(6, at: 5)
shoppinglist.insert("Chocolate", at: 4)
to remove an item in the array with the remove(at:) method:
number.remove(at: 0)
shoppinglist.remove(at: 0)
number.removeLast()
shoppinglist.removeLast()
number.removeAll()
shoppinglist.removeAll()
good luck :
(+=)
number += [1,2,3,4]
shoppinglist += ["Bred"]
number.removeLast()
shoppinglist.removeLast()
number.removeAll()
shoppinglist.removeAll()
good luck :
Comments
please post any question and comment right here so that i can support for you
Post a Comment