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
错误:无法将'AnyObject'类型的值转换为预期的参数类型@noscape(AnyObject)throws - > Bool
I don't know how to fix it
我不知道如何解决它
1 个解决方案
#1
1
-
String
is not an object, so it does not conform to protocolAnyObject
. UseAny
instead. - Neither
AnyObject
norAny
isEquatable
, so functioncontains
doesn't know how to compare elements of the array withotherArrayElement
.
String不是对象,因此它不符合协议AnyObject。请改用Any。
AnyObject和Any都不是Equatable,因此function contains不知道如何将数组的元素与otherArrayElement进行比较。
Why do you need to use arrays of Any
elements ? Why don't you use arrays of String
s ? What else do you want to store in them ?
为什么需要使用Any元素的数组?你为什么不使用字符串数组?你还想在其中存储什么?
#1
1
-
String
is not an object, so it does not conform to protocolAnyObject
. UseAny
instead. - Neither
AnyObject
norAny
isEquatable
, so functioncontains
doesn't know how to compare elements of the array withotherArrayElement
.
String不是对象,因此它不符合协议AnyObject。请改用Any。
AnyObject和Any都不是Equatable,因此function contains不知道如何将数组的元素与otherArrayElement进行比较。
Why do you need to use arrays of Any
elements ? Why don't you use arrays of String
s ? What else do you want to store in them ?
为什么需要使用Any元素的数组?你为什么不使用字符串数组?你还想在其中存储什么?