1
    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 Answer 1

1
  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 ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.