Rakesh
Rakesh

Reputation: 302

Core data crash fetching

Here is the what the crash report says :-

Fatal Exception: NSInvalidArgumentException -[_PFFetchPlanHeader _genericValueForKey:withIndex:flags:]: unrecognized selector sent to instance 0x282b24730

The part of the code where the crash is happening :-

    let managedContext = CoreDataHelper.getNSMangedObjectContext()
    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: NotificationPersistenceHelper.UserNotification_entity)
    fetchRequest.predicate = NSPredicate(format: "\(NotificationPersistenceHelper.uniqueID) = %@", argumentArray: [uniqueId!])
    do{
         let results = try managedContext.fetch(fetchRequest)

        return  !results.isEmpty
    }catch let error as NSError{
        AppDelegate.getAppDelegate().log.error("Fetch Failed : \(error.localizedDescription)")
    }
    return false

the crash is happening at the following line from the above code:-

  let results = try managedContext.fetch(fetchRequest)

Any help on why the crash is happening guys tried a lot but was not able to find the reason for the crash. Any help guys?.... Thanks in advance

Upvotes: 0

Views: 226

Answers (1)

VishalPethani
VishalPethani

Reputation: 852

Instead of this

fetchRequest.predicate = NSPredicate(format: "\(NotificationPersistenceHelper.uniqueID) = %@", argumentArray: [uniqueId!])

Try this one

fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(NotificationPersistenceHelper.uniqueID), uniqueId!)

Upvotes: 1

Related Questions