Skip to content

Conversation

woxtu
Copy link
Contributor

@woxtu woxtu commented Jun 23, 2023

This PR fixes UserDefaults.string(forKey:) behavior for number values. Resolves #3362.
https://developer.apple.com/documentation/foundation/userdefaults/1416700-string

UserDefaults.standard.set(true, forKey: "key1")
UserDefaults.standard.set(42, forKey: "key2")
UserDefaults.standard.set(12.34 as Float, forKey: "key3")
UserDefaults.standard.set(12.34, forKey: "key4")
UserDefaults.standard.set("1234", forKey: "key5")

// on macOS
UserDefaults.standard.string(forKey: "key1") // "1"
UserDefaults.standard.string(forKey: "key2") // "42"
UserDefaults.standard.string(forKey: "key3") // "12.34"
UserDefaults.standard.string(forKey: "key4") // "12.34"
UserDefaults.standard.string(forKey: "key5") // "1234"

// on Linux
UserDefaults.standard.string(forKey: "key1") // nil
UserDefaults.standard.string(forKey: "key2") // nil
UserDefaults.standard.string(forKey: "key3") // nil
UserDefaults.standard.string(forKey: "key4") // nil
UserDefaults.standard.string(forKey: "key5") // "1234"

@woxtu woxtu force-pushed the userdefaults-string branch from 790baf1 to 0f3bf15 Compare June 24, 2023 13:15
@compnerd
Copy link
Member

@swift-ci please test

@compnerd compnerd merged commit c0cd1d1 into swiftlang:main Jul 21, 2023
@woxtu
Copy link
Contributor Author

woxtu commented Jul 22, 2023

Thanks!

@woxtu woxtu deleted the userdefaults-string branch July 22, 2023 12:29
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.

[SR-15124] UserDefaults string(forKey:) behaves different on Linux and macOS
2 participants