Swift Learning-----Dictionary

Source: Internet
Author: User

//Dictionary (unordered data set)*the dictionary type of Swift is bridged to the Nsdictionary class of the foundation. * Format [:]/Dictionary<key, value>()*Let immutable dictionary*var variable dictionary//Note:*the key type of a dictionary must follow the Hashable protocol//declaring a dictionaryLet dict: [string:double]//Initialize DictionaryDict = ["score":99.9]//dict = ["Age": +]//define an empty dictionaryLet Dict1 =[String:int] ()//to define a dictionary with values//[String:nsobject] Type is the most common type of iOS developmentvar dict2 = ["name":"SSC"," Age": to,"score":59.5]//Getdict2["name"]                       //Increase//as long as there is no corresponding key in the dictionary will be addeddict2["Rank"] =1Dict2//DeleteDict2.removevalueforkey ("Rank") dict2 ["Name": "SSC", "age": +, "score": 59.5]//Traverse forKeyinchdict2.keys{Print (key)} forValueinchdict2.values{Print (value)} for(Key, value)inchdict2{print (key) print (value)}//Mergingvar dict3 = ["name":"SSC"," Age": to]var Dict4= ["Rank":1,"score":99.9] for(Key, value)inchdict4 {Dict3[key]=value}dict3 ["Score": 99.90000000000001, "age": +, "rank": 1, "name": "SSC"]

Swift Learning-----Dictionary

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.