ios - 核心数据崩溃获取

标签 ios swift core-data

这是崩溃报告的内容:-

致命异常:NSInvalidArgumentException -[_PFFetchPlanHeader _genericValueForKey:withIndex:flags:]: 无法识别的选择器发送到实例 0x282b24730

发生崩溃的代码部分:-

    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

崩溃发生在上述代码的以下行:-

  let results = try managedContext.fetch(fetchRequest)

关于为什么会发生崩溃的任何帮助,人们都尝试了很多,但无法找到崩溃的原因。有什么帮助吗?....提前致谢

最佳答案

代替这个

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

试试这个

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

关于ios - 核心数据崩溃获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53605662/

相关文章:

ios - 从 swift 三元运算符返回引用

ios - 如何更新核心数据输入值

iphone - iOS - 在后台执行写入核心数据的多个 AFJSONRequestOperations

ios - 表格 View 选择新 View

iphone - 来自同一 iPhone/XCode4 项目的多个可执行文件

ios - Firebird 和 Swift 兼容性?

ios - 添加输出设置时,Swift Dictionary 为零

ios - 如何防止用户输入密码时文本移动?

ios - 每 5 个应用程序打开显示全屏广告

ios - 在 RestKit 中使用 RKObjectManager 从 CoreData 获取数据