Make OrderedDictionary keys generic

This commit is contained in:
Michael Kirk 2019-03-27 16:11:28 -06:00
parent 4e8e41c327
commit 1357449dcc
2 changed files with 8 additions and 11 deletions

View file

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

View file

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