Map array of objects to Dictionary in Swift

前端 未结 9 505
半阙折子戏
半阙折子戏 2021-01-30 00:32

I have an array of Person\'s objects:

class Person {
   let name:String
   let position:Int
}

and the array is:

         


        
9条回答
  •  离开以前
    2021-01-30 01:08

    Maybe something like this?

    myArray.forEach({ myDictionary[$0.position] = $0.name })
    

提交回复
热议问题