How to compare two strings ignoring case in Swift language?

后端 未结 16 2583
孤街浪徒
孤街浪徒 2020-12-13 05:28

How can we compare two strings in swift ignoring case ? for eg :

var a = \"Cash\"
var b = \"cash\"

Is there any method that will return tru

16条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 06:09

    You can just write your String Extension for comparison in just a few line of code

    extension String {
    
        func compare(_ with : String)->Bool{
            return self.caseInsensitiveCompare(with) == .orderedSame
        } 
    }
    

提交回复
热议问题