ios没有提供简单的汉字拼音排序方法,在网上看到了oc方法,这里写以下对应的swift方法
var stringCompareBlock: (String,String)->Bool = { (str1:String, str2:String) -> Bool in var nsStr1 = str1 as NSString var nsStr2 = str2 as NSString var encode:NSStringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)) var temp1:NSString = nsStr1.stringByAddingPercentEscapesUsingEncoding(encode)! var temp2:NSString = nsStr2.stringByAddingPercentEscapesUsingEncoding(encode)! return temp1.compare(temp2) == NSComparisonResult.OrderedAscending }
oc的方法链接如下: