import WinSDK // Swift Dictionary to IMap Adaptor extension Dictionary { public func toMap() -> AnyIMap { DictionaryMap(self) } } internal class DictionaryMap : IMap where K : Hashable { typealias T = AnyIKeyValuePair? private var storage: Dictionary internal init(_ storage: Dictionary){ self.storage = storage } var size : UInt32 { UInt32(storage.count) } func hasKey(_ K: K) -> Bool { storage[K] != nil } func lookup(_ K: K) -> V { storage[K]! } func getView() -> AnyIMapView? { DictionaryMapView(storage) } @discardableResult func insert(_ K: K, _ V: V) -> Bool { // WinRT returns true if replacing storage.updateValue(V, forKey: K) != nil } func remove(_ K: K) { storage.removeValue(forKey: K) } func clear() { storage.removeAll(keepingCapacity: true) } func first() -> AnyIIterator? { fatalError("Not implemented: ArrayVector.First") } } extension DictionaryMap { public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil } } internal class DictionaryMapView : IMapView where K : Hashable { typealias T = AnyIKeyValuePair? private var storage: Dictionary internal init(_ storage: Dictionary){ self.storage = storage } var size : UInt32 { UInt32(storage.count) } func hasKey(_ key: K) -> Bool { storage[key] != nil } func lookup(_ key: K) -> V { storage[key]! } func split( _ first: inout AnyIMapView?, _ second: inout AnyIMapView?) { fatalError("Not implemented: DictionaryMapView.Split") } func first() -> AnyIIterator? { fatalError("Not implemented: ArrayVector.First") } } extension DictionaryMapView { public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil } }