字符串比较
实在想不出怎么用一条语句既做到按字符串长度排序又可以按照首字母顺序两个同时排序,所以干脆用试试用链式编程,没想到还真可以。。在swift2.0中写的
var strArr=["d","cd","bcd","abcd","abc","ab","a"]
strArr.sort()
func compareTwoString(s1:String , s2:String)->Bool{
return s1.characters.count<s2.characters.count //|| s1.characters.first<s2.characters.first
}
func compareTwoString2(s1:String , s2:String)->Bool{
return s1.characters.first<s2.characters.first
}
strArr.sort(compareTwoString2).sort(compareTwoString)