我的所有 CoreData UnitTests 都有以下代码设置(context
我的viewContext
和Item
CoreData 模型在哪里):
override func setUpWithError() throws {
let deleteReq = NSBatchDeleteRequest(fetchRequest: Item.fetchRequest())
try context.execute(deleteReq)
}
现在,我在声明时收到此错误deleteReq
:
必须在初始化期间提供获取请求 (NSInvalidArgumentException)
我这样设置我的控制器:
let testController = PersistenceController(inMemory: true)
// #### - ####
init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "AppName")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
// [...]
return
})
}
难道我做错了什么?