original articles, welcome reprint. Reprint Please specify: Dongsheng's blog
Array ( Array ) is an ordered set of elements of the same type. The collection elements in the array are ordered and can recur.
declares a Array type, you can use one of the following statements.
var studentlist1:array<string> var studentList2: [String] Declares an Array that is not available and needs to be initialized
, Array types are often initialized at the same time as they are declared. The sample code is as follows:
var studentlist1:array<string> = ["Zhang San", "John Doe", "Harry", "Dong Liu"] var studentlist2:[string] = ["Zhang San", "John Doe", "Harry", "Dong Liu"] Let Studentlist3:[string] = ["Zhang San", "John Doe", "Harry", "Dong Liu"] var studentList4 = [String] ()
Array traversal
The most common operation of an array is traversal, which is to take each element of the array out and manipulate or calculate it. The entire traversal process is inseparable from the loop, and the for-in loop can be used .
The following is a sample code that iterates through an array:
var studentlist:[string] = ["Zhang San", "John Doe", "Harry"] for item in studentlist {print (item)} for (index, value) Instudentli St.enumerate () {print ("Item \ (index + 1): \ (Value)")}
The results of the operation are as follows:
Tom
John doe
Harry
Item 1: Zhang San
Item 2: John Doe
Item 3: Harry
Welcome to follow Dongsheng Sina Weibo@tony_Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
650) this.width=650; "title=" 00.png "src=" http://s5.51cto.com/wyfs02/M01/7C/A6/wKioL1bVEDry6ahBAAAs2MBEZnc748.png "alt=" Wkiol1bvedry6ahbaaas2mbeznc748.png "/>
More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php
This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://tonyguan.blog.51cto.com/701759/1746242
Learn Swift from scratch Learning Notes (day)--swift array Collection