Beginner Swift Notebook dictionary, Array (iv)

Source: Internet
Author: User

1 Import Foundation2 //the Order of the dictionary elements is unordered3 //1. The dictionary element is a key-value pair (Key:value)4 //key must be a hash string\int\bool5 vardic1=["name":"LSQ"]6println (dic1["name"])7 //the complete definition method8 vardic2:dictionary<string,any>=["a":1,"b":"b"]9 println (DIC2)Ten  One //2. Operation of the dictionary A vardic3=["Apple":"Apple","Bag":"Package"] -println (dic3["Apple"])//Enquiry -dic3["Apple"]="Chestnut"//Modify theprintln (dic3["Apple"]) -Dic3.updatevalue ("Apple", Forkey:"Apple")//Save, return key value to the value of the optional type update failed return value is nil -println (dic3["Apple"]) -println (dic3["Apples"])//access to a nonexistent key gets an empty nil +  -Dic3.updatevalue ("Apple AAA", Forkey:"Apples")//modified to return a key value to an optional type of value update failed the return value is nil if the element is not added + println (DIC3) A  atdic3["LSQ"]="Liu Shiqun" //Add an element - println (DIC3) -  -Dic3.removevalueforkey ("LSQ")//deletes the specified key to return the removed value if key does not return nil in the dictionary - println (DIC3) - //Dic3.removeall (keepcapacity:true)//Delete all as an array parameter indicates whether the dictionary capacity is preserved in  - //the traversal of a dictionary to  for(Key,value)inchDIC3 { +println"key:\ (Key) value:\ (value)") - } the  * //Keys Values $ println (Array (Dic3.keys))Panax Notoginseng println (dic3.values) -  the  forKeyinchdic3.keys{ + println (Key) A } the  forValueinchdic3.values{ + println (value) -}

Beginner Swift Notebook dictionary, Array (iv)

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.