Since Any does not conform to Equatable, [Any] does not have a contains(_:) method. You cannot use == to compare Anys either.
However, [Any] does have a contains(where:) method that accepts a predicate. You can pass in a (Any) -> Bool and if there is anything in the array that makes the closure return true, contains returns true.
We can use contains(where:) to do exactly what you want. For example, if you want to check for ele2:
a.contains(where: { ($0 as? String) == ele2 })
What I did is that I casted the element to string first, then use ==.
You can also create an extension that does this:
extension Array where Element == Any {
func contains<T: Equatable>(_ element: T) -> Bool {
return contains(where: { ($0 as? T) == element })
}
}