DebugDescription macro causing “String Interpolation” warnings

Using the DebugDescription macro to display an optional value produces a “String interpolation produces a debug description for an optional value” build warning.

For example:

@DebugDescription
struct MyType: CustomDebugStringConvertible {
    let optionalValue: String?
    public var debugDescription: String {
        "Value: \(optionalValue)"
    }
}

The DebugDescription macro does not allow (it is an error)

"Value: \(String(describing: optionalValue))"

or

"Value: \(optionalValue ?? "nil")"

because “Only references to stored properties are allowed.”

Is there a way to reconcile these?

I have a build log full of these warnings, obscuring real issues.

Answered by DTS Engineer in 825845022

I was hoping to get back to this question (primarily as an excuse to play with this new feature :-) but at this point that doesn’t seem likely. If you’re still stuck, I recommend you ask about this over on Swift Forums. It’s likely that folks over there will be able to help out.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I was hoping to get back to this question (primarily as an excuse to play with this new feature :-) but at this point that doesn’t seem likely. If you’re still stuck, I recommend you ask about this over on Swift Forums. It’s likely that folks over there will be able to help out.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for following up. I did get a bit of help on the Swift Forums. Not a solution but at least to know I’m not missing anything, and a means of partially hiding the warnings: here.

DebugDescription macro causing “String Interpolation” warnings
 
 
Q