How to compare two strings ignoring case in Swift language?
Use caseInsensitiveCompare
method:
let a = "Cash"let b = "cash"let c = a.caseInsensitiveCompare(b) == .orderedSameprint(c) // "true"
ComparisonResult tells you which word comes earlier than the other in lexicographic order (i.e. which one comes closer to the front of a dictionary). .orderedSame
means the strings would end up in the same spot in the dictionary