Navigation Menu

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-11943] Outdated documentation for numericCast(_:) #54363

Closed
swift-ci opened this issue Dec 11, 2019 · 3 comments
Closed

[SR-11943] Outdated documentation for numericCast(_:) #54363

swift-ci opened this issue Dec 11, 2019 · 3 comments
Assignees
Labels
good first issue Good for newcomers improvement standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11943
Radar rdar://problem/57888487
Original Reporter bzamayo (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, StarterBug, StarterDocs
Assignee @natecook1000
Priority Medium

md5: e13604a2bc1f0808504231367a9bedab

Issue Description:

The documentation for this standard library could be improved in a few ways. Discussion of modern constructor syntax for type conversions should be included (like `UInt32(value)` or `Int(value)` or whatever), as generally that is the preferred Swift language idiom over calling `numericCast`.

However, my main reason for filing the bug is the example code is outdated:

func random(in range: Range<Int>) -> Int {
    return numericCast(arc4random_uniform(numericCast(range.count)))
        + range.lowerBound
}

It uses `numericCast` twice in the context of creating a random number generation function. Clearly, this example was written before the standard library incorporated native random APIs. This example should be changed to something outside of the random number domain, as inventing `random(in🙂` functions ad-hoc (and especially calls to `arc4random_uniform`) from Swift should no longer be encouraged as good practice.

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@ArielDemarco
Copy link

Hi @beccadax! This seems to be already fixed here

@beccadax
Copy link
Contributor

Yup. Fixed by #31464.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants