Learn Swift from scratch Learning Notes (day)--swift array Collection

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.