2017-10-10 48 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)") 
}