1Let array1 = ["ABC","EFG"]2Let array2 = ["CCC",4]4 println (array2);5 6 vararray3:string[]=["ABC","DDD"]//the array type is specified. Requires that each array element be a string. 7 8Let array4:string[] =array19 Tenarray1[0] ="XYZ" One Aprintln (ARRAY4)//XYZ,EFG - - varIntarray = int[] ()//Create an int type the - varFourInts1 = int[] (count:4, Repleatedvalue:2) - - varStrArray1 = ["ABC","BB"] + varStrArray2 = ["XXX","yyy"] - varStrarray = StrArray1 +StrArray2 +println (Strarray)//[abc,bb,xxx,yyy] is not the addition of each array element, the type of each array element must be identical when added. A at -strarray1[0...1] = ["XYZ","DDD"] -println (StrArray1)//[XYZ,DDD] -strarray2[0..1] = ["XYZ","DDD"] -println (StrArray2)//[XYZ,DDD,XYZ] Three points are left closed right closed. Two points indicate left closed right open, XYZ inserted in the position of XXX, but ddd no place, so inserted in the second element xyz front (the value of the assignment is more than the index, will be inserted in the back of the Element). If you need to assign the correct value, change it to strarry2[0..2].
Three points: Closed interval
Two points: Left closed right open interval
1 strarray1[0... 1] = ["xyz","ddd","UUU" ]2 println (strArray1) //[xyz,ddd,uuu] 3 4 in front of only two assignments, then the last number will be inserted into the final position, forming a third element.
Creation and initialization of swift--arrays