Swift 5.x Dictionary和KeyValuePai

2020-06-26  本文已影响0人  ShenYj

Dictionary的创建


var dict1 = Dictionary<String, Int>()
var dict2 = [String: Int]()
var dict3: Dictionary<String, Int> = [:]

如果你需要保持顺序的kv对可以使用KeyValuePairs


let recordTimes: KeyValuePairs = ["Florence Griffith-Joyner": 10.49,
                                  "Evelyn Ashford": 10.76,
                                  "Evelyn Ashford": 10.79,
                                  "Marlies Gohr": 10.81]
print(recordTimes.first!)

输出结果:

(key: "Florence Griffith-Joyner", value: 10.49) 
上一篇下一篇

猜你喜欢

热点阅读