Swift Basic _ Data structure

Source: Internet
Author: User

Whoa, shove! The data structure in Swift is like this, it is a concise ah, not much to say the code to get:

Import Foundationprint ("Hello, world!.") var p1= -//String is the class string inside SwiftLet P2 ="value is"+String (p1) print ("P2 is \ (p2)") var p3= ["IOS","Android","WP"] forIinchp3{Print ("I is \ (i)")}//modified the No. 0 item of the array.p3[0] ="Ios/swift" forIinchp3{Print ("I1 is \ (i)")}//append an element after the P3 arrayP3.append ("Symbian") forIinchp3{Print ("i2 is \ (i)")}//Define a dictionaryvar P4 = [    "name":"XZR",    " Age":" -",    "score":" -",]//dictionary with [] preceded by key is the value for(Key,value)inchp4{Print ("key value \ (key) = \ (value)")}//Append content to the dictionaryp4["Course"] ="IOS"; for(Key,value)inchp4{Print ("key value2 \ (key) = \ (value)")}let P5=P4.keys forKeyinchp5{Let v=P4[key] Print ("key is \ (key) = \ (v)")    }//tuple "In fact array"Let numbers = [    "IOS":[1,2,3,5,6],    "Android":[ -, at, $, the],    "WP":[ +, the, the]]var Sum:int=0 for(Key,value)inchnumbers{ forIinchvalue{sum+=i}} Print ("sum is \ (sum)")

Command + R, you'll know.

Oh, Jiangzi, have you made it?

Swift Basic _ Data structure

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.