Iterating Through a Dictionary in Swift

后端 未结 7 727
醉话见心
醉话见心 2020-11-27 12:12

I am a little confused on the answer that Xcode is giving me to this experiment in the Swift Programming Language Guide:

// Use a for-in to iterate through a         


        
7条回答
  •  情书的邮戳
    2020-11-27 12:35

    This is a user-defined function to iterate through a dictionary:

    func findDic(dict: [String: String]){
        for (key, value) in dict{
        print("\(key) : \(value)")
      }
    }
    
    findDic(dict: ["Animal":"Lion", "Bird":"Sparrow"])
    //prints Animal : Lion 
             Bird : Sparrow
    

提交回复
热议问题