Skip to content
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

Fix UserDefaults.integer(forKey:) behavior #4781

Merged
merged 1 commit into from Jul 22, 2023

Conversation

woxtu
Copy link
Contributor

@woxtu woxtu commented Jun 24, 2023

This PR fixes UserDefaults.integer(forKey:) behavior for boolean and floating-point values.
https://developer.apple.com/documentation/foundation/userdefaults/1407405-integer

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.integer(forKey: "key1") // 1
UserDefaults.standard.integer(forKey: "key2") // 42
UserDefaults.standard.integer(forKey: "key3") // 12
UserDefaults.standard.integer(forKey: "key4") // 12
UserDefaults.standard.integer(forKey: "key5") // 1234

// on Linux
UserDefaults.standard.integer(forKey: "key1") // 0
UserDefaults.standard.integer(forKey: "key2") // 42
UserDefaults.standard.integer(forKey: "key3") // 0
UserDefaults.standard.integer(forKey: "key4") // 0
UserDefaults.standard.integer(forKey: "key5") // 1234

@compnerd
Copy link
Collaborator

@swift-ci please test

@compnerd
Copy link
Collaborator

@swift-ci please test Linux platform

@compnerd compnerd merged commit 8fbe624 into apple:main Jul 22, 2023
3 checks passed
@woxtu woxtu deleted the userdefaults-integer branch July 24, 2023 12:11
@woxtu
Copy link
Contributor Author

woxtu commented Jul 24, 2023

Thanks!

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.

None yet

2 participants