Tuples (tuples) are significantly different from arrays and dictionaries, which make up multiple values into a composite value:
404 Error = (404,"notFound")//HTTP 404 is of type (INT, String), the value is (404, "not Found")
You can name a single element when you define a tuple, and the array of tuples has some similarities:
$ " OK ")
Arrays and dictionaries (Dictionary) are collections of the same data type, and the dictionary is in the form of a key-value pair, and the array has only values. But the array is actually a special dictionary whose keys correspond to an ordered natural number starting from 0.
The difference between inserting and appending elements of an array:
var arraytest = ["hello"]arraytest.insert ("Swift", Atindex:1)// method of inserting elements arraytest.append ("Swift" )// methods for appending elements
The following is the basic usage of the dictionary:
Creation of dictionaries:
//two ways to create a dictionaryvar mychildren:dictionary<string,string> = [ " First":"Mao" "Second":"er Mao" "Third":"Sanmao"]var Mydog= [1:"Rhubarb"2:"Erhuang"3:"Xiao Huang"]
Read the dictionary (query):
mychildren["First"]// return to "Da Mao"mydog[3] // back to "little yellow"
The traversal of the dictionary:
// get all the values of the dictionary for inch mydog.values{ Print ("value:\ (Value)") }
Tuples, arrays, dictionaries in Swift