In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to use Dictionary in swift". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use Dictionary in swift.
Define / / define whether var dic1 = Dictionary () var dic2 = [String: Int] () var dic3: Dictionary = [:] var dic = ["zhang san": 18, "li si": 19, "wang wu": 20] is empty & number of elements print (dic.isEmpty) / / falseprint (dic.count) / / 3 traversal / / unordered traversal dictionary for (key, value) in dic {print ("name:\ (key)) Age:\ (value) ")} / * name: li si, age:19name: wang wu, age:20name: zhang san, age:18*/// ordered traversal for key in dic.keys.sorted () {print (" name:\ (key), age:\ (dic [key]!) ")} / * name: li si, age:19name: wang wu, age:20name: zhang san, age:18*/update//updatedic [" zhang san "] = 19print (dic) / / [" li si ": 19 "wang wu": 20, "zhang san": 19] / updateValuedic.updateValue (20, forKey: "zhang san") print (dic) / / ["li si": 19, "wang wu": 20, "zhang san": 20] remove//removedic ["zhang san"] = nilprint (dic) / / ["li si": 19 "wang wu": 20] / / removeValueprint (dic.removeValue (forKey: "li si")) / / Optional (19) print (dic) / / ["wang wu": 20] merge//mergevar mergeDic = ["a": 1, "b": 2] mergeDic.merge (["a": 3, "c": 4]) {(current, _) in current} print (mergeDic) / / [c ": 4," a ": 1 "b": 2] mergeDic.merge (["a": 3, "d": 6]) {(_, new) in new} print (mergeDic) / / ["b": 2, "c": 4, "a": 3, "d": 6] so far I believe you have a deeper understanding of "how to use Dictionary in swift", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.