Reputation: 433
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
Upvotes: 2
Views: 8951
Reputation: 11555
You can't compare string and array of strings, but you can use contains
:
if barcodeTypes.contains(metadataObj.type)
Upvotes: 3
Reputation: 588
It looks like you are trying to check if any strings in your barCodeTypes
array match metadataObj.type
. You want a for in loop.
for barCode in barCodeTypes {
if metadataObj.type == barCode {
//the code...
}
}
This iterates over every item in barCodeTypes
and checks if they are equal.
Upvotes: -1