Swift Core Data Predicate IN Clause

I’m attempting to use an IN clause with an NSPredicate. I’m getting the following error:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa000000000000611’

  • linker error with ShareKit ios
  • UICollectionView auto scroll to cell at IndexPath
  • ALAssetsLibrary getting the path of a video and play it later
  • Swift stringByEvaluatingJavaScriptFromString
  • Change the listing order of the view controllers in Xcode storyboard
  • IOS pushViewController without tabBar and navigationBar
  • Here’s the code:

    let fetchRequest: NSFetchRequest<Employee> = NSFetchRequest(entityName: "Employee")
    fetchRequest.sortDescriptors = [
         NSSortDescriptor.init(key: "lastName", ascending: true)
    fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", argumentArray: recentEmployeeIds)
    fetchedResultsController = NSFetchedResultsController.init(fetchRequest: fetchRequest,
                                                                               managedObjectContext: FLCoreDataController.shared.mainObjectContext,
                                                                               sectionNameKeyPath: nil,
                                                                               cacheName: nil)
    fetchedResultsController?.delegate = self
    try? fetchedResultsController?.performFetch()

    Any ideas as to what the problem is?

    Solutions Collect From Internet About “Swift Core Data Predicate IN Clause”

    You don’t show how you are defining recentEmployeeIds, but assuming its something like

    let recentEmployeeIds:[Int] = ...

    then you need to init the NSPredicate correctly. There is no label for argumentArray

    fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", recentEmployeeIds)