In my model, I have a property category
of type Category
(en Enum represented by an Int16). I want to use the new SortDescriptor with the category
property but the compiler complains that No exact matches in call to initializer
. It's working fine with the rawCategory, or if I use a NSSortDescriptor.
Is there a way to make it work with the enum instead?
class Book: NSObject {
var category: Category
var rawCategory: Int16
init(category: Category) {
self.category = category
self.rawCategory = category.rawValue
}
}
enum Category: Int16 {
case actionAdventure
case classics
case comic
case detective
case fantasy
}
func makeSortDescriptor() {
let categorySortDescriptor = SortDescriptor(\Book.category) // No exact matches in call to initializer
let rawCategorySortDescriptor = SortDescriptor(\Book.rawCategory)
let categoryNSSortDescriptor = NSSortDescriptor(keyPath: \Book.category, ascending: true)
}