diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 2186b0a..5ef1e9b 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -90,3 +90,17 @@ extension Defaults.Key { self.init(key, default: nil, suite: suite) } } + +extension Defaults.AnyKey: Equatable { + public static func == (lhs: Defaults.AnyKey, rhs: Defaults.AnyKey) -> Bool { + lhs.name == rhs.name + && lhs.suite == rhs.suite + } +} + +extension Defaults.AnyKey: Hashable { + public func hash(into hasher: inout Hasher) { + hasher.combine(name) + hasher.combine(suite) + } +} diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index 8483234..c7034a7 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -639,4 +639,12 @@ final class DefaultsTests: XCTestCase { cancellable.cancel() waitForExpectations(timeout: 10) } + + func testKeyEquatable() { + XCTAssertEqual(Defaults.Key("equatableKeyTest", default: false), Defaults.Key("equatableKeyTest", default: false)) + } + + func testKeyHashable() { + _ = Set([Defaults.Key("hashableKeyTest", default: false)]) + } }