`func countingLastOccurrence(filterkey1: String) -> Int {
let context = PersistenceController.shared.container.viewContext
let fetchquest1 = NSFetchRequest<Filedetails>(entityName: "Filedetails")
fetchquest1.sortDescriptors = [NSSortDescriptor(keyPath: \Filedetails.year, ascending: false), NSSortDescriptor(keyPath: \Filedetails.sequence, ascending: false)]
fetchquest1.predicate = NSPredicate(format: "%K == 1", filterkey1)
let item1 = try? context.fetch(fetchquest1).firstIndex
let item1a = item1.compactMap { Int($0) }
return item1a`
Hello, I would like to ask how to convert the result of the fetchquest which is an optional to an Int ?
Value of type '((Filedetails) -> Array.Index?)?' (aka 'Optional<(Filedetails) -> Optional>') has no member 'compactMap'
I had tried to force unwrapped it :
let item1a = item1 ?? 0
but it show "Binary operator '??' cannot be applied to operands of type '((Filedetails) -> Array.Index?)?' (aka 'Optional<(Filedetails) -> Optional>') and 'Int'"
Thank you so much.