Skip to content

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

Merged
merged 3 commits into from
Apr 3, 2018
Merged

Fixed NSString/Swift.String Bridging in Locale
 #1474

merged 3 commits into from
Apr 3, 2018

Conversation

pvieito
Copy link
Contributor

@pvieito pvieito commented Mar 13, 2018

  • Fixed NSString/Swift.String Bridging in Locale

  • Added support for Preferred Languages in Linux
  • Added tests for Locale static properties and methods

@pvieito
Copy link
Contributor Author

pvieito commented Mar 13, 2018

@swift-ci please test

let euroCurrencyCode = "EUR"
let spainRegionCode = "ES"
let galicianLanguageCode = "gl"
let galicianLocaleIdentifier = Locale.identifier(fromComponents: [NSLocale.Key.languageCode.rawValue: galicianLanguageCode,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the hoop jump through languageCode.rawValue here? The argument type is [String: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.

Any suggestions? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -109,39 +109,39 @@ extension NSLocale {
open class var isoLanguageCodes: [String] {
var identifiers = Array<String>()
for obj in CFLocaleCopyISOLanguageCodes()._nsObject {
identifiers.append((obj as! NSString)._swiftObject)
identifiers.append(obj as! String)
Copy link
Contributor

@parkera parkera Mar 13, 2018

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 to Swift.String?

Copy link
Contributor Author

@pvieito pvieito Mar 13, 2018

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:

Could not cast value of type 'Swift.String' (0x7ffff3e61970) to 'Foundation.NSString' (0x7ffff75a9190).

Copy link
Contributor

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:

_SwiftValue.fetch(CFLocaleCopyISOLanguageCodes()) as? [String] ?? []

That's the least confusing primitive for bridging on Linux.

Copy link
Contributor Author

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.

@alblue
Copy link
Contributor

alblue commented Mar 13, 2018

@swift-ci please test

@pvieito
Copy link
Contributor Author

pvieito commented Mar 13, 2018

@swift-ci please test

@pvieito
Copy link
Contributor Author

pvieito commented Mar 22, 2018

Could anyone start the CI test, please?

@millenomi
Copy link
Contributor

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Mar 28, 2018

@swift-ci please test

@pvieito
Copy link
Contributor Author

pvieito commented Apr 2, 2018

Any idea why is the CI test not being executed? 🤔

@millenomi
Copy link
Contributor

@swift-ci please test

@pvieito
Copy link
Contributor Author

pvieito commented Apr 3, 2018

Great! 👍

@millenomi
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 161ab81 into swiftlang:master Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants