Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[6.2][stdlib] Allow a default for optional interpolations #81360

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

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from

Conversation

natecook1000
Copy link
Member

Cherry-pick of #80547 for the 6.2 release branch.


Explanation: This cherry picks the implementation of SE-0477 to add a string interpolation method with a default: parameter for optional interpolation values.
Main Branch PR: #80547
Risk: Low.
Reviewed By: @stephentyrone
Resolves: rdar://150865613
Testing: New tests for the string interpolations and fix-its.

This adds an `appendInterpolation` overload to
`DefaultStringInterpolation` that includes a parameter for providing a
default string when the value to interpolate is `nil`. This allows this
kind of usage:

```swift
let age: Int? = nil
print("Your age is \(age, default: "timeless")")
// Prints "Your age is timeless"
```

The change includes an additional fixit when optional values are
interpolated, with a suggestion to use this `default:` parameter.
@natecook1000 natecook1000 requested a review from a team as a code owner May 7, 2025 17:55
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test Windows platform

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.

2 participants