Skip to content

NSLocale.hash: Implement #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Foundation/NSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding {

return locale.localeIdentifier == localeIdentifier
}


override open var hash: Int {
return localeIdentifier.hash
}

open func encode(with aCoder: NSCoder) {
guard aCoder.allowsKeyedCoding else {
preconditionFailure("Unkeyed coding is unsupported.")
Expand Down
9 changes: 9 additions & 0 deletions TestFoundation/TestNSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TestNSLocale : XCTestCase {
("test_constants", test_constants),
("test_Identifier", test_Identifier),
("test_copy", test_copy),
("test_hash", test_hash),
("test_staticProperties", test_staticProperties),
("test_localeProperties", test_localeProperties),
]
Expand Down Expand Up @@ -102,6 +103,14 @@ class TestNSLocale : XCTestCase {
XCTAssertTrue(locale == localeCopy)
}

func test_hash() {
let a1 = Locale(identifier: "en_US")
let a2 = Locale(identifier: "en_US")

XCTAssertEqual(a1, a2)
XCTAssertEqual(a1.hashValue, a2.hashValue)
}

func test_staticProperties() {
let euroCurrencyCode = "EUR"
let spainRegionCode = "ES"
Expand Down