Skip to content

Fix for SR-3634: Error while accessing Locale.availableIdentifiers #944

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
Apr 11, 2017
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
2 changes: 1 addition & 1 deletion Foundation/NSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension NSLocale {
open class var availableLocaleIdentifiers: [String] {
var identifiers = Array<String>()
for obj in CFLocaleCopyAvailableLocaleIdentifiers()._nsObject {
identifiers.append((obj as! NSString)._swiftObject)
identifiers.append(obj as! String)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At runtime type of 'obj' is received as String and the caste from Swift.String to Foundation.NSString fails.

}
return identifiers
}
Expand Down
7 changes: 6 additions & 1 deletion TestFoundation/TestNSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class TestNSLocale : XCTestCase {
return [
("test_constants", test_constants),
("test_Identifier", test_Identifier),
("test_copy", test_copy)
("test_copy", test_copy),
("test_availableIdentifiers", test_availableIdentifiers),
]
}

Expand Down Expand Up @@ -107,4 +108,8 @@ class TestNSLocale : XCTestCase {

XCTAssertTrue(locale == localeCopy)
}

func test_availableIdentifiers() {
XCTAssertNoThrow(Locale.availableIdentifiers)
}
}