Swift - Convert Array to Dictionary

后端 未结 7 1520
轻奢々
轻奢々 2021-02-15 12:00

I just want convert an array of Player Names into a dictionary Scoreboard, giving everyone an initial score of 0.

Meaning...

var playerNames =          


        
7条回答
  •  终归单人心
    2021-02-15 12:23

    Here is how you can do that:

    var playerNames = ["Harry", "Ron", "Hermione"]
    
    var dictionary = [String: Int]()
    for player in playerNames {
        dictionary[player] = 0
    }
    

提交回复
热议问题