I am trying to have nil for zeroth index element and rest will have value of Generic type T which is Comparable.
So when I initialise it will nil it works as expected
struct Container<T: Comparable> {
var container = [T?]()
init() {
container.append(nil)
}
}
but when I do it with an integer say 0, I get ambiguous reference
struct Container<T: Comparable> {
var container = [T?]()
init() {
container.append(0)
}
}
Playground execution failed: error: Algorithms.playground:7:9: error: ambiguous reference to member 'append'
container.append(0)
^~~~~~~~~
I want to understand why this error is occurring?
Tis not necessaryInt– it could beString, and0cannot be added to a[String?].