When I try to use this method the compiler shows the next error: "Type 'UIView' does not conform to protocol 'IntegerLiteralConvertible'"
if find(_views, 1) {
}
When I try to use this method the compiler shows the next error: "Type 'UIView' does not conform to protocol 'IntegerLiteralConvertible'"
if find(_views, 1) {
}
That method signature is:
find(domain: C, value: C.Generator.Element) -> C.Index?
Where C
is a typed array, C.Generator.Element
is the type of the elements in that array, and C.Index?
is an optional that will contain the index the element is found at, if found at all.
So the error you are getting is because it looking at the instances in your array UIView
and trying to compare them to 1
which is an IntegerLiteral
. And UIView
is not IntegerLiteralConvertible
because it would make no sense to convert a view to an integer.
So find
will return the index where some instances can be found in an array of those instances.
var strings: [String] = ["A", "B", "C"]
find(strings, "C")! // 2
But you don't seem to want the index. if find(views, 1)
seems to indicate to me that you want to check if index 1
exists in the array. If this is really what you want, you can do this very simply by checking the count.
if _views.count > 1 {
println("index 1 exists in this array")
}