我有以下代码按字母顺序按升序排序字典数组。但是我在大写字母后面得到了排序的小写字母键值。恩。如果键的值为" Jast"," rat"," Put" ," put"," Avi"," Que" 。我的输出类似于" Avi",#34; Jast"," Put"," Que"," put" ,"老鼠"哪个没有排序。我使用了以下代码
let sortedArray = (
episode_ParticipantList as NSArray
).sortedArrayUsingDescriptors(
[NSSortDescriptor(key: "FirstName", ascending: true)])
as!
[[String:AnyObject]]
答案 0 :(得分:2)
IN SWIFT 4
responseData = responseData.sorted { ($0["firstname"] as! String).localizedCaseInsensitiveCompare($1["firstname"] as! String) == ComparisonResult.orderedAscending }
答案 1 :(得分:1)
怎么样:
let sortedArray = episode_ParticipantList.sort{
$0["FirstName"]?.lowercaseString < $1["FirstName"]?.lowercaseString
}
这可能会更快,但您需要测试:
import Foundation
let sortedArray = episode_ParticipantList.sort{
$0["FirstName"]!.caseInsensitiveCompare($1["FirstName"]!) == .OrderedAscending
}