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-15627] String(describing:) does not correctly handle Bool wrapped in NSNumber #57923

Open
sindresorhus opened this issue Dec 20, 2021 · 0 comments

Comments

@sindresorhus
Copy link

@sindresorhus sindresorhus commented Dec 20, 2021

Previous ID SR-15627
Radar None
Original Reporter @sindresorhus
Type Bug
Environment

Swift 5.5

Xcode 13.2.1

macOS 12.1

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

md5: a3c7c78c5651e5eb010deee760cefe10

Issue Description:

String(describing: NSNumber(true))
//=> "1"

I expected it to print:

"true"

Possible solution: Internally, String(describing:​) can first check if the value is NSNumber and if so, do this comparison to check if the underlying value is a Bool:

nsNumber == kCFBooleanTrue || nsNumber == kCFBooleanFalse

Lack of this makes debugging more difficult, and also makes it annoying to use JSONSerialization which return Bool values wrapped in NSNumber.

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

No branches or pull requests

1 participant