CoreData NSBatchUpdateRequest问题

时间:2019-07-01 13:23:35

标签: ios swift iphone database core-data

xdatamodel

“ report”,“ workType”,“ timeType”,“ activity”,“ project”是可选的。

我想设置报告,workType,timeType,活动,项目为零。

我已经尝试过

   do {
            let updateRequest = NSBatchUpdateRequest(entityName: "TimerTable")
            updateRequest.predicate = NSPredicate(format: "user == %@ ", user)
            updateRequest.resultType = .updatedObjectsCountResultType

            var propertiesToUpdate: [AnyHashable : Any] = [:]
            for column in ["report", "workType", "timeType", "activity", "project"] {
                propertiesToUpdate[column] = NSNull()
            }

            updateRequest.propertiesToUpdate = propertiesToUpdate
            let result =  try AppDelegate.database.context.execute(updateRequest) as? NSBatchUpdateResult

            print("Reset Timer count: \(result?.result ?? 0)")
        } catch {
            print("delete error: \(error)")
        }
its throws Fatal Exception: NSInvalidArgumentException

AND

do {
            let updateRequest = NSBatchUpdateRequest(entityName: "TimerTable")
            updateRequest.predicate = NSPredicate(format: "user == %@ ", user)
            updateRequest.resultType = .updatedObjectsCountResultType

            var propertiesToUpdate: [AnyHashable : Any] = [:]
            for column in ["report", "workType", "timeType", "activity", "project"] {
                propertiesToUpdate[column] = NSExpression(forConstantValue: nil)
            }

            updateRequest.propertiesToUpdate = propertiesToUpdate
                let result =  try AppDelegate.database.context.execute(updateRequest) as? NSBatchUpdateResult

            print("Reset Timer count: \(result?.result ?? 0)")
        } catch {
            print("delete error: \(error)")
        }

its throws Fatal Exception: NSInvalidArgumentException
Invalid relationship ((<NSRelationshipDescription: 0x2823046e0>), name report, isOptional 1, isTransient 0, entity TimerTable, renamingIdentifier report, validation predicates ( ), warnings ( ), versionHashModifier (null) userInfo { }, destination entity TimeReport, inverseRelationship timerEvents, minCount 0, maxCount 1, isOrdered 0, deleteRule 1) passed to propertiesToUpdate:

我在这里缺少什么以及如何解决此问题

0 个答案:

没有答案