I am trying to understand the difference between these two code
func swapTwo<String>(_ a: inout String, _ b: inout String) {
let temp = a
a = b
b = temp
}
func swapTwo<S>(_ a: inout S, _ b: inout S) {
let temp = a
a = b
b = temp
}
The Data Type Color used in swapTwo<String> code is Blue, where as in swapTwo<S> the Data Type is graying out, Should it not be graying out equally in both the codes.
to the compiler, these functions are identical (really!) and you are probably getting a duplicate declaration error. but iām guessing you probably intended to write
func swapTwo(_ a: inout String, _ b: inout String) {
let temp = a
a = b
b = temp
}
note that the concrete type String does not appear in angle brackets.
Your editor might also have a special case for String, thinking "oh, this is always going to be Swift.String, I'll be helpful and highlight it differently" and not realizing that the user is allowed to name things String as well. Not that I recommend making a habit of it, since humans, too, might get confused.