0

I am trying to see if my UITextField.text matches any of the strings in my array exactly. As I am using letters I need to know if the text matches exactly and not just contains elements from the array.

In the if statement I am not sure what to put after 'cameraBodies' to search over the whole array?

Thank you for any help

let cameraBodies = ["A","B","C","D","E","F","G","H","I","J","K",
                    "L","M","N","O","P","Q","R","S","T","U","V",
                    "W","X","Y","Z","Other"]

if cameraBodyTextField.text != cameraBodies (Here is the problem) {     
            print("Does not match")
        } else {    
            print("Does match")
        }
}
spoax
  • 471
  • 9
  • 29
  • Could you provide an example of what you are expecting from different cameraBodyTextField.text values? You can just use the contains function (https://developer.apple.com/documentation/swift/array/2945493-contains) – LorenzOliveto Aug 29 '18 at 15:10

1 Answers1

1

Use if cameraBodies.contains(cameraBodyTextField.text!) { ... }.
For more help check this array contains.

Paprikadobi
  • 114
  • 1
  • 6