-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixed NSString/Swift.String Bridging in Locale #1474
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ class TestNSLocale : XCTestCase { | |
("test_constants", test_constants), | ||
("test_Identifier", test_Identifier), | ||
("test_copy", test_copy), | ||
("test_availableIdentifiers", test_availableIdentifiers), | ||
("test_staticProperties", test_staticProperties), | ||
("test_localeProperties", test_localeProperties), | ||
] | ||
} | ||
|
@@ -110,10 +110,29 @@ class TestNSLocale : XCTestCase { | |
XCTAssertTrue(locale == localeCopy) | ||
} | ||
|
||
func test_availableIdentifiers() { | ||
XCTAssertNoThrow(Locale.availableIdentifiers) | ||
func test_staticProperties() { | ||
let euroCurrencyCode = "EUR" | ||
let spainRegionCode = "ES" | ||
let galicianLanguageCode = "gl" | ||
let galicianLocaleIdentifier = Locale.identifier(fromComponents: [NSLocale.Key.languageCode.rawValue: galicianLanguageCode, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the hoop jump through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any suggestions? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the types are all consistent with Darwin :( so, not an issue that concerns this patch specifically. |
||
NSLocale.Key.countryCode.rawValue: spainRegionCode]) | ||
|
||
XCTAssertTrue(galicianLocaleIdentifier == "\(galicianLanguageCode)_\(spainRegionCode)") | ||
|
||
let components = Locale.components(fromIdentifier: galicianLocaleIdentifier) | ||
|
||
XCTAssertTrue(components[NSLocale.Key.languageCode.rawValue] == galicianLanguageCode) | ||
XCTAssertTrue(components[NSLocale.Key.countryCode.rawValue] == spainRegionCode) | ||
|
||
XCTAssertTrue(Locale.availableIdentifiers.contains(galicianLocaleIdentifier)) | ||
XCTAssertTrue(Locale.commonISOCurrencyCodes.contains(euroCurrencyCode)) | ||
XCTAssertTrue(Locale.isoCurrencyCodes.contains(euroCurrencyCode)) | ||
XCTAssertTrue(Locale.isoRegionCodes.contains(spainRegionCode)) | ||
XCTAssertTrue(Locale.isoLanguageCodes.contains(galicianLanguageCode)) | ||
|
||
XCTAssertTrue(Locale.preferredLanguages.count == UserDefaults.standard.array(forKey: "AppleLanguages")?.count ?? 0) | ||
} | ||
|
||
func test_localeProperties(){ | ||
#if os(Android) | ||
XCTFail("Locale lookup unavailable on Android") | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the result type here
CFStringRef
, which is not directly bridgeable toSwift.String
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, they are
Swift.String
. If you try to get any of that properties in the actual Swift Foundation implementation they will throw with the following execution:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent this kin of confusion, can we just replace the whole thing with:
That's the least confusing primitive for bridging on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I'll commit the changes.