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? you can use word.lowercaseString to convert the string to all lowercase characters let list = ["kashif"] let word = "Kashif" if contains(list, {$0.caseInsensitiveCompare(word) == NSComparisonResult.OrderedSame}) { println(true) // true } Xcode 7.3.1 • Swift 2.2.1 if list.contains({$0.caseInsensitiveCompare(word) == .OrderedSame}) { print