2017-10-10 20 views
1

如何根据土耳其语排序fetchResult,在结果结尾处排序土耳其字符。土耳其语区域的Swift排序FetchRequest结果

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)") 
    } 
+0

我发现溶液通过改变NSSortDescriptor(标号: “名字”,上升:真)至NSSortDescriptor(标号: “名字”,上升:真,选择器:#selector (NSString.localizedCaseInsensitiveCompare))。 – oburan

+0

如果您可以发布您找到的解决方案作为答案,这样会很好,这样搜索的其他人就可以获得帮助。 – Sneha

回答

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)") 
}