swiftcore-datanssortdescriptor

CoreData localized sorting


I need to sort data in CoreData entity containing special national characters. I have NSSortDescriptor as follows

let sorting = [NSSortDescriptor(keyPath: \Books.bokName, ascending: true)]
    

and found hint here iPhone CoreData - How to fetch managed objects, and sorting them ignoring case? Unfortunately it seems that newer vesrion of Swift included in XCode 12.3 doesn`t support selector parameter anymore. What other options I have?


Solution

  • Well, I realized that I have to use

    NSSortDescriptor(key: "bokName", ascending: true, selector: #selector(NSString.localizedStandardCompare))
    

    instead of init with keyPath.