Array: brackets [] means that the array values are separated by commas 1, and if the array is declared as a constant, it cannot be modified by itself, and the values in the array cannot be modified &NBSP;2, specifying the type of array, syntax:array<type> can be abbreviated to [type] &NBSP;&NB Sp &NBSP;VAR&NBSP;TYPEARRAY1: [String] &NBS P;var typearray1:array<int> = [1, 2, 3] 3, if an array is declared, but the array is not initialized, Cannot be quoted var typeArray1: [String] & nbsp; &NBSP;PRINTLN (typeArray1) Error!! 4, a Swift type array when the element type is detected in the array &nbs P Nsarray array of OC when the element type is different in the array, &NBSP;&NBSP ; if you want to become nsmutablearRay is explicitly declared: var myarray:nsmutablearray = [1, 2, "XYZ"] var t ypearray3:array<int> = [1, 3, "XYZ"] is wrong, the last element is not a reshape 5, var nullarray = [] creates an array type of Nsarray because the Swift compiler cannot infer the type of the array 6, create an empty array of Swift & nbsp var nullArray1 = [Int] () &N Bsp var nullarray2:array<float> = [] &NBSP;&N Bsp var nullArray3: [String] = [] 7, create an array of type Int with length 4 initialized, and all four elements are initialized to 2& nbsp var fourints = [Int] (Count:4, repeatedvalue:2) 8, array addition is a merged array 9, array interval assignment: Multiple array elements can be assigned at the same time &N BsP 1) interval range and right-hand assignment element number are different, elements are inserted,, the interval is large to remove the extra interval,,, & nbsp 2) var arrayname[min. <max] = [Item1, item2, item3] and nbsp Max and Min exceed the upper and lower bounds of the array, then throw the exception directly 10, append, insert, Remoteall no return value removelast, Removeatindex return value, return removed value & nbsp empty count calculates the number of elements 11, which can be assigned with compound addition &NB sp;+= to append elements of an array 12, enumerate elements in an array & nbsp; 1) for...in variable or subscript line &NBSP;2) for (index, value) in enumerate (fourints) {} Dictionary: using brackets[], Key-value is separated by commas, key:value form 1, if the key and value in the dictionary are not String types, you do not need to enclose it in double quotation marks Up 2, var employ1:dictionary<string, string> = ["Name": "Bill", "Price": "345 "] var employ2: [string:string]] = [" Name ":" Bill " , "Price": "345"] var employ3 = [' Name ': ' Bill ', ' Price ': "345"] 3, different types are OC type nsdictonary, to nsmutabledictonary then explicitly declare & nbsp 4, if let is declared, not only means the dictionary itself cannot be repaired, the value in its dictionary cannot be modified 5, var nullDict1 = dictionary& Lt;int, string> () var nullDict2 = [int:string] () & nbsp; 6, Dict[key] = value with original key modified, no add 7, Updatevalu The E method returns the value before the modification &NBSP dict[key] = nil Delete key-value &NBSP;&NBSP;&N Bsp removevalueforkey Specify the key to delete data, and return the data to be deleted value 8, var dict1 = ["Key1": "A", "Key2": "Abd"] //String converted to INT type, you need to use optional type variable var value1:int? = dict1["Key1"]?. ToInt () var dict2 = ["Key1": "+", "Key2": 123] //Int class The NSObject type value of type is converted to INT type, not optional type but to add! var value2:int = dict2["Key2"] as! int //String type NSObject type value is converted to INT type, requires optional type var value3:in T? = (dict2["Key1"] as? String)?. ToInt () 9, for (key, value) in dict{} for key in dict.keys{} keys, Values Properties When the dictionary type becomes nsdictonary, you can convert it to Dictionary before using the keys and the valuesKey and value 10, convert keys and values to an array var dict = ["Key1": "Val1", "Key2": "Val2"]Let keys = Array (Dict.keys)
Swift Arrays and dictionaries