Fix support for non-string keys in dictionaries (#149)
This commit is contained in:
parent
11b6adbfcb
commit
3efef5a28e
|
@ -132,7 +132,7 @@ extension Array: Defaults.Serializable where Element: Defaults.Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Dictionary: Defaults.Serializable where Key: LosslessStringConvertible & Hashable, Value: Defaults.Serializable {
|
extension Dictionary: Defaults.Serializable where Key: LosslessStringConvertible & Hashable, Value: Defaults.Serializable {
|
||||||
public static var isNativelySupportedType: Bool { Value.isNativelySupportedType }
|
public static var isNativelySupportedType: Bool { (Key.self is String.Type) && Value.isNativelySupportedType }
|
||||||
public static var bridge: Defaults.DictionaryBridge<Key, Value> { Defaults.DictionaryBridge() }
|
public static var bridge: Defaults.DictionaryBridge<Key, Value> { Defaults.DictionaryBridge() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,15 @@ final class DefaultsDictionaryTests: XCTestCase {
|
||||||
XCTAssertEqual(Defaults[key]["0"], [newName, fixtureArray[1]])
|
XCTAssertEqual(Defaults[key]["0"], [newName, fixtureArray[1]])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testIntKey() {
|
||||||
|
let fixture = [1: "x"]
|
||||||
|
let key = Defaults.Key<[Int: String]>("independentDictionaryIntKey", default: fixture)
|
||||||
|
XCTAssertEqual(Defaults[key][1], fixture[1])
|
||||||
|
let newValue = "John"
|
||||||
|
Defaults[key][1] = newValue
|
||||||
|
XCTAssertEqual(Defaults[key][1], newValue)
|
||||||
|
}
|
||||||
|
|
||||||
func testType() {
|
func testType() {
|
||||||
XCTAssertEqual(Defaults[.dictionary]["0"], fixtureDictionary["0"])
|
XCTAssertEqual(Defaults[.dictionary]["0"], fixtureDictionary["0"])
|
||||||
let newName = "Chen"
|
let newName = "Chen"
|
||||||
|
|
Loading…
Reference in New Issue