Check If A String Exists In An Array Case Insensitively
Answer : Xcode 8 • Swift 3 or later let list = ["kashif"] let word = "Kashif" if list.contains(where: {$0.caseInsensitiveCompare(word) == .orderedSame}) { print(true) // true } alternatively: if list.contains(where: {$0.compare(word, options: .caseInsensitive) == .orderedSame}) { print(true) // true } if you would like to know the position(s) of the element in the array (it might find more than one element that matches the predicate): let indices = list.indices.filter { list[$0].caseInsensitiveCompare(word) == .orderedSame } print(indices) // [0] You can also use localizedStandardContains method which is case and diacritic insensitive: func localizedStandardContains<T>(_ string: T) -> Bool where T : StringProtocol Discussion This is the most appropriate method for doing user-level string searches, similar to how searches are done generally in the system. The search is locale-aware, case and diacritic insensitive. The exact list of s...