Swift 2.0 Syntax Dictionary

Source: Internet
Author: User

: Playground-noun:a place where people can play

Import UIKit

/*:

Dictionary

* and OC difference

* 1. {} replaced by []

* 2. Remove All @

* variable dictionary var

* immutable dictionary let

*/

var dict = ["name": "Lnj", "Age":

Let dict2: [String : nsobject] = ["name": "Lnj", "Age": 30< c28>]

Anyobject = = NSObject

Let dict3: Dictionary<String, anyobject> = ["name": "Lnj", "Age":

Note : in Enterprise Development , the most frequently used dictionary type is [String:anyobject]

Let dict4 = [String: anyobject] ()

Take value

Dict["name"]

Update

If you assign a value to an existing key , It is the update

Dict["name"] = "Zs"

Dict

Increase

If you assign a value to a nonexistent key , It is added

Dict["score"] = 99.9

Dict

Delete

Dict. Removevalueforkey("name")

Dict

Traverse

For key in dict. Keys

{

Print(dict[key])

}

The key in the dictionary is assigned to K, and the value in the dictionary is assigned to v

Note : K and v write casually , but note that key must be assigned to the previous traversal , value must be assigned to the back of a traversal

for (key, value) in dict

{

print(key)

print(value)

}

Swift 2.0 Syntax 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.