I have an array of Person\'s objects:
Person
class Person { let name:String let position:Int }
and the array is:
extension Array { func mapToDict(by block: (Element) -> T ) -> [T: Element] where T: Hashable { var map = [T: Element]() self.forEach{ map[block($0)] = $0 } return map } }