arraysswiftstringcontains

Check if a string exists in an array case insensitively


Declaration:

let listArray = ["kashif"]
let word = "kashif"

then this

contains(listArray, word) 

Returns true but if declaration is:

let word = "Kashif"

then it returns false because comparison is case sensitive.

How to make this comparison case insensitive?


Solution

  • you can use

    word.lowercaseString 
    

    to convert the string to all lowercase characters