Swift按土耳其语语言环境排序FetchRequest结果

时间:2017-10-10 07:11:58

标签: swift core-data

如何按土耳其语排序fetchResult,在结果末尾排序的土耳其字符。

let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
    let fetch = NSFetchRequest<Contact>(entityName: "Contact")
    let sortDescriptor = NSSortDescriptor(key: "firstName", ascending: true)
    let sortDescriptors = [sortDescriptor]
    fetch.sortDescriptors = sortDescriptors
    do {
        let list = try managedObjectContext.fetch(fetch)
    } catch {
        fatalError("Failed \(error)")
    }

1 个答案:

答案 0 :(得分:0)

工作代码:

let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
let fetch = NSFetchRequest<Contact>(entityName: "Contact")
let sortDescriptor = NSSortDescriptor(key: "firstName", ascending: true, selector: #selector(NSString.localizedCaseInsensitiveCompare))
let sortDescriptors = [sortDescriptor]
fetch.sortDescriptors = sortDescriptors
do {
    let list = try managedObjectContext.fetch(fetch)
} catch {
    fatalError("Failed \(error)")
}