Given that both Strings and Ints can be used in string interpolation
First of all, you need to distinguish string interpolation of which type. In case of Text, the type is LocalizedStringKey, not String.
So, you may need to find how string interpolation of LocalizedStringKey is working.
LocalizedStringKey.StringInterpolation
As far as I read the parts Appending to an Interpolation and Instance Methods, I cannot find a common protocol which would work both for String and Int.
So, one possible work around, which does not need any protocols, would be converting theVariable to String before applying string interpolation of LocalizedStringKey.
struct MySubView<T>: View {
@Binding var theVariable: T
var body: some View {
HStack {
Text("This part isn't important")
Text("But this is \(String(describing: theVariable))")
}
}
}
With this, you can use any arbitrary type for T, and with making the type conform to CustomStringConvertible, you can control the result of string interpolation for your custom type.