Creating array using array is similar in swift and objective c.
Ex:
var numbers = ["one", "two", "three", "four"]
numbers[1] = "ten"
numbers[1] = "ten"
In this example the value of numbers first position value is changed to "ten"
var dicVal = [
"bruce Lee": "Fighter",
"Jordan": "Mechanic",
]
dicVal["Jordan"] = "Automobile Engineer"
var dicVal = [
"bruce Lee": "Fighter",
"Jordan": "Mechanic",
]
dicVal["Jordan"] = "Automobile Engineer"
let emptyArray = [String]()
let emptyDictionary = [String: Float]()
let emptyDictionary = [String: Float]()
If type information can be inferred, you can write an empty array as
[]
and an empty dictionary as [:]
—for example, when you set a new value for a variable or pass an argument to a function.
shoppingList = []
occupations = [:]
occupations = [:]
var shoppingList : [String] = ["Unknown", "Arab"] println("The shopping list contains \(shoppingList.count) items.") if shoppingList.isEmpty { println("The shopping list is empty.") } else { println("The shopping list is not empty.") } shoppingList.append("Spanish") shoppingList += ["French"] var firstItem = shoppingList[0] shoppingList[0] = "English" shoppingList[0...3] = ["Chines", "Hindi"] shoppingList.insert("Italian", atIndex: 0) let mapleSyrup = shoppingList.removeAtIndex(0)
No comments:
Post a Comment