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

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

Closed
Nef10 opened this issue Aug 27, 2021 · 1 comment · Fixed by #4780
Closed

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

Nef10 opened this issue Aug 27, 2021 · 1 comment · Fixed by #4780

Comments

@Nef10
Copy link

Nef10 commented Aug 27, 2021

Previous ID SR-15124
Radar rdar://problem/82537716
Original Reporter @Nef10
Type Bug
Environment

Swift 5.4

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 3414fbf73d52305cd8edd91052896a16

Issue Description:

import Foundation
UserDefaults.standard.set(2, forKey: "a")
print(UserDefaults.standard.integer(forKey: "a"))
print(UserDefaults.standard.string(forKey: "a") ?? "it is nil")

On Linux it outputs:
2
it is nil

On macOS:
2
2

The documentation states:

For string values, the string associated with the specified key; for number values, the string value of the number. Returns nil if the default does not exist or is not a string or number value

Which makes the macOS behaviour correct

@typesanitizer
Copy link

cc @millenomi

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants