1
votes
    let otherArray:[AnyObject] = ["a","aa","aaa"]
    let otherArrayElemnt = otherArray[0]
    let myArray:[AnyObject] = ["qq"]
    if myArray.contains(otherArrayElemnt){     //<<<<<<< Error HERE
        //if contains...doSomething
    }else{
        //none doSomething
    }

Error: Cannot convert value of type 'AnyObject' to expected argument type @noscape (AnyObject) throws -> Bool

I don't know how to fix it

1

1 Answers

1
votes
  1. String is not an object, so it does not conform to protocol AnyObject. Use Any instead.
  2. Neither AnyObject nor Any is Equatable, so function contains doesn't know how to compare elements of the array with otherArrayElement.

Why do you need to use arrays of Any elements ? Why don't you use arrays of Strings ? What else do you want to store in them ?