Make OrderedDictionary keys generic

pull/2/head
Michael Kirk 6 years ago
parent 4e8e41c327
commit 1357449dcc

@ -11,7 +11,7 @@ import UIKit
// as immutable, once configured. // as immutable, once configured.
public class ImageEditorContents: NSObject { public class ImageEditorContents: NSObject {
public typealias ItemMapType = OrderedDictionary<ImageEditorItem> public typealias ItemMapType = OrderedDictionary<String, ImageEditorItem>
// This represents the current state of each item, // This represents the current state of each item,
// a mapping of [itemId : item]. // a mapping of [itemId : item].
@ -72,7 +72,7 @@ public class ImageEditorContents: NSObject {
@objc @objc
public func items() -> [ImageEditorItem] { public func items() -> [ImageEditorItem] {
return itemMap.orderedValues() return itemMap.orderedValues
} }
@objc @objc

@ -4,16 +4,13 @@
import Foundation import Foundation
public class OrderedDictionary<ValueType>: NSObject { public class OrderedDictionary<KeyType: Hashable, ValueType> {
public typealias KeyType = String private var keyValueMap = [KeyType: ValueType]()
var keyValueMap = [KeyType: ValueType]() public var orderedKeys = [KeyType]()
var orderedKeys = [KeyType]() public init() { }
public override init() {
}
// Used to clone copies of instances of this class. // Used to clone copies of instances of this class.
public init(keyValueMap: [KeyType: ValueType], public init(keyValueMap: [KeyType: ValueType],
@ -25,7 +22,7 @@ public class OrderedDictionary<ValueType>: NSObject {
// Since the contents are immutable, we only modify copies // Since the contents are immutable, we only modify copies
// made with this method. // made with this method.
public func clone() -> OrderedDictionary<ValueType> { public func clone() -> OrderedDictionary<KeyType, ValueType> {
return OrderedDictionary(keyValueMap: keyValueMap, orderedKeys: orderedKeys) return OrderedDictionary(keyValueMap: keyValueMap, orderedKeys: orderedKeys)
} }
@ -90,7 +87,7 @@ public class OrderedDictionary<ValueType>: NSObject {
return orderedKeys.count return orderedKeys.count
} }
public func orderedValues() -> [ValueType] { public var orderedValues: [ValueType] {
var values = [ValueType]() var values = [ValueType]()
for key in orderedKeys { for key in orderedKeys {
guard let value = self.keyValueMap[key] else { guard let value = self.keyValueMap[key] else {

Loading…
Cancel
Save