0

I am using Xcode 13.4.1 and Swift 5. I have a searchBar delegate in which I am trying to search for the string inside the searchBar from a core data entity called Item. I am getting the following error:

[error] error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x60000311df80> , unimplemented SQL generation for predicate : (title CONTAINS[cd] "Aib") with userInfo of (null)

There are not many answers available online and the ones that are available are very old ones in Objective-C and has not worked so far for me. How can I do this with the latest version of Swift.

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

    let request: NSFetchRequest<Item> = Item.fetchRequest()
    request.predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchBar.text!)
    request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]

    do {
        itemArray = try context.fetch(request)
        toDoListTableView.reloadData()
    }
    catch {
        print("search error \(error)")
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ghazalah
  • 233
  • 2
  • 14
  • 2
    Some answers to similar questions mentions that the attribute is unavailable, double check the spelling of `title` in your Core Data model. Otherwise you could enable core data debugging using the launch argument “ -com.apple.CoreData.SQLDebug 4” and see if that reveals anything – Joakim Danielson Aug 18 '22 at 05:06
  • You might want to use `#keyPath(Item.title)` instead of hard coded string, and use `%K` for the placeholder, if that's really an non-existent attribute? is `title` a String property of `Item`? – Larme Aug 19 '22 at 09:32

0 Answers0