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
to convert the string to all lowercase characters
For checking if a string exists in a array with more Options(caseInsensitive, anchored/search is limited to start)
using Foundation
range(of:options:)
SWIFT 3.0:
Finding a case insensitive string in a string array is cool and all, but if you don't have an index it can not be cool for certain situations.
Here is my solution:
This is better than the other answers b/c you have index of the object in the array, so you can grab the object and do whatever you please :)
Xcode 7.3.1 • Swift 2.2.1
Xcode 8 • Swift 3 or later
alternatively:
For checking if a string exists in a array (case insensitively), please use
where listArray is the name of array and word is your searched text
This code works in Swift 2.2
Try this: