How would one implement a bidirectional map in Swift?
I am currently in need of a performant bidirectional map. In Swift, a dictionary can be reversed, however, that will return a tuple of the types it is made of, not a counterpart dictionary. Is there a library for that or does someone have ideas on how to address this issue? Thanks With Swift 4 you could easily make your own using a generic struct: struct BidiMap<F:Hashable,T:Hashable> { private var _forward : [F:T]? = nil private var _backward : [T:F]? = nil var forward:[F:T] { mutating get { _forward = _forward ?? [F:T](uniqueKeysWithValues:_backward?.map{($1,$0)} ?? [] ) return _forward! }