Skip to content

Commit 3c95c9c

Browse files
authored
Merge pull request #1647 from lorentey/NSLocale.hash
2 parents 277c1f1 + ad9169f commit 3c95c9c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Foundation/NSLocale.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding {
6969

7070
return locale.localeIdentifier == localeIdentifier
7171
}
72-
72+
73+
override open var hash: Int {
74+
return localeIdentifier.hash
75+
}
76+
7377
open func encode(with aCoder: NSCoder) {
7478
guard aCoder.allowsKeyedCoding else {
7579
preconditionFailure("Unkeyed coding is unsupported.")

TestFoundation/TestNSLocale.swift

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TestNSLocale : XCTestCase {
1313
("test_constants", test_constants),
1414
("test_Identifier", test_Identifier),
1515
("test_copy", test_copy),
16+
("test_hash", test_hash),
1617
("test_staticProperties", test_staticProperties),
1718
("test_localeProperties", test_localeProperties),
1819
]
@@ -102,6 +103,14 @@ class TestNSLocale : XCTestCase {
102103
XCTAssertTrue(locale == localeCopy)
103104
}
104105

106+
func test_hash() {
107+
let a1 = Locale(identifier: "en_US")
108+
let a2 = Locale(identifier: "en_US")
109+
110+
XCTAssertEqual(a1, a2)
111+
XCTAssertEqual(a1.hashValue, a2.hashValue)
112+
}
113+
105114
func test_staticProperties() {
106115
let euroCurrencyCode = "EUR"
107116
let spainRegionCode = "ES"

0 commit comments

Comments
 (0)