When specifically dealing with non-optional String
values, what could be the difference between String interpolation and String concatenation?
struct MyModel {
let value1: String
let value2: String
var displayNameByConcatenation: String {
return value1 + "-" + value2
}
var displayNameByInterpolation: String {
return "\(value1)-\(value2)"
}
}
- Is there going to be any case where
displayNameByConcatenation
anddisplayNameByInterpolation
are different? Like on long unicode strings? - Is it possible to somehow override the behavior of operator
+
or the behavior of interpolation to make them different in above example? - Is one faster/slower than the other?
Note that from this question we learn that string interpolation will use the description
of a CustomStringConvertible. But does String
concatenation (operator +
) also calls the description
?