Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

variables - Many ways of defining a Swift dictionary

In swift there are quite a few ways on defining a dictionary. So, are all of these identical?

var dic1 = Dictionary<String, Int>()

var dic2 = [String:Int]()

var dic3: Dictionary = Dictionary<String, Int>()

var dic4: Dictionary = [String:Int]()

var dic5: Dictionary<String, Int> = Dictionary<String, Int>()

var dic6: Dictionary<String, Int> = [String: Int]()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, all these 6 lines do produce the same result:

  • an empty
  • mutable
  • dictionary
  • where the key has type String
  • and the value has type Int

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...