binary operator '==' cannot be applied to operands of type 'String!' and '[String]' in Swift 2 Xcode 7

bbkrz

I have developed the following code and it's working fine:

if metadataObj.type == AVMetadataObjectTypeQRCode {
    //the code...
}

Now, I would like for metadataObj.type to be equal to an array of string like the following:

let barCodeTypes = [AVMetadataObjectTypeQRCode,
                    AVMetadataObjectTypeAztecCode
]

if metadataObj.type == barcodeTypes {
    //The code...
}

I get the following error when I use the new code:

binary operator '==' cannot be applied to operands of type 'String!' and '[String]'

Any suggestions? Thanks in advance

MirekE

You can't compare string and array of strings, but you can use contains:

 if barcodeTypes.contains(metadataObj.type)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

binary operator '==' cannot be applied to operands of type NSDictionary and String in swift 3

concatenate in swift: Binary operator '+' cannot be applied to operands of type 'String' and 'AnyObject'

Binary operator '==' cannot be applied to operands of type 'Any?' and 'String' Swift iOS

Binary operator '+' cannot be applied to operands of type '_' and 'String'

Binary operator '+' cannot be applied to operands of type 'String' and '() -> String'

Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

Binary operator '>' cannot be applied to operands of type '(String?)' and 'String?'

Binary operator '+' cannot be applied to operands of type 'String' and 'String?'

Swift - Binary operator cannot be applied to operands of type

Swift 2: Binary operator '==' cannot be applied to operands of type '()?' and 'Bool'

Operator '-' cannot be applied to operands of type string and string

operator <= cannot be applied to operands of type string and string

Binary operator '+' cannot be applied to two String operands

Binary operator "&&" cannot be applied to two String operands

Binary operator '>' cannot be applied to two 'String?!' operands

Binary operator '!=' cannot be applied to two '[[String]]' operands

Operator >= cannot be applied to operands of type string and datetime

"Operator '==' cannot be applied to operands of type 'char' and 'string'"

operator '||' cannot be applied to operands of type string and bool

Operator '==' cannot be applied to operands of type string and Enum

Operator '-' cannot be applied to operands of type 'float' and 'string'

Operator '==' cannot be applied to operands of type string and char

Operator '>' cannot be applied to operands of type 'object' and 'string'

Operator '!=' cannot be applied to operands of type 'DateTime' and 'string'

Operator '==' cannot be applied to operands of type 'DateTime' and 'string'

Binary operator '+=' cannot be applied to operands of type '[Dictionary<String, String>]' and 'Dictionary<String, String>'

Swift: '!=' cannot be applied to operands of type 'String' and 'Any'

concatenate in swift3.0: Binary operator '+' cannot be applied to operands of type '[]' and '[]?'

Binary operator cannot be applied to operands of type int and int? Swift 3