skip
skip copied to clipboard
ExpressibleByStringInterpolation constructor is not inferred for non-interpolated string parameters
This is related to https://github.com/skiptools/skip/issues/64 . We want to be able to implement SkipUI.Text like so:
public struct Text {
public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil) {
…
}
public init(verbatim string: String) {
…
}
}
And be able to create the Text with a localized key. When the string contains an interpolation (e.g., Text("Name: \(username)"), then the LocalizedStringKey constructor is inferred correctly. But if just do Text("Name") with no interpolated arguments, the string sent to the String(verbatim:) constructor, which is not what we want.
The workaround is to explicitly use a LocalizedStringKey in the Text initializer, as seen at https://github.com/skiptools/skip-ui/blob/main/Tests/SkipUITests/SkipUITests.swift#L320