当我尝试注销时,清除核心数据中的所有数据
public func deleteCoreData(completion: @escaping (Bool) -> Void) {
if let psc = context.persistentStoreCoordinator {
if let store = psc.persistentStores.last {
let storeUrl = psc.url(for: store)
context.perform({
self.context.reset()
do {
try psc.remove(store)
try FileManager.default.removeItem(at: storeUrl)
try psc.destroyPersistentStore(at: storeUrl,
ofType: NSSQLiteStoreType,
options: nil)
try psc.addPersistentStore(ofType: NSSQLiteStoreType,
configurationName: nil,
at: storeUrl,
options: nil)
} catch {
print(error)
}
completion(true)
})
}
}
}
但是它崩溃了1/10次
Thread 0 Crashed:
0 CoreData 0x00000001870b3e44 _nameForEntityDescription + 8
1 CoreData 0x00000001870b3e20 -[NSSQLCore entityForFetchRequest:] + 40
2 CoreData 0x00000001872b9af0 -[NSSQLFetchRequestContext initWithRequest:context:sqlCore:] + 584
3 CoreData 0x000000018721b45c -[NSSQLObjectFaultRequestContext createFetchRequestContext] + 120
4 CoreData 0x00000001872bdeb0 _executeObjectFaultRequest + 80
5 CoreData 0x00000001872be644 _executeNewRowValuesForObjectFaultRequest + 184
6 CoreData 0x000000018721b498 -[NSSQLObjectFaultRequestContext executeRequestCore:] + 16
7 CoreData 0x0000000187121000 -[NSSQLStoreRequestContext executeRequestUsingConnection:] + 244
8 CoreData 0x00000001871a3ba4 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 80
9 libdispatch.dylib 0x00000001840c0a60 _dispatch_client_callout + 12
10 libdispatch.dylib 0x00000001840c95bc _dispatch_queue_barrier_sync_invoke_and_complete + 52
11 CoreData 0x00000001871a3aa0 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 252
12 CoreData 0x00000001872940cc -[NSSQLCoreDispatchManager routeStoreRequest:] + 260
13 CoreData 0x00000001871d58f8 -[NSSQLCore dispatchRequest:withRetries:] + 232
14 CoreData 0x00000001870c3ab0 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 316
15 CoreData 0x00000001870e1ef4 -[NSPersistentStoreCoordinator(_NSInternalMethods) _conflictsWithRowCacheForObject:withContext:andStore:] + 144
16 CoreData 0x00000001870e1698 -[NSPersistentStoreCoordinator(_NSInternalMethods) _checkRequestForStore:withContext:originalRequest:andOptimisticLocking:] + 1560
17 CoreData 0x00000001871b0d34 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 1512
18 CoreData 0x00000001871a9758 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 264
19 CoreData 0x00000001870b3130 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 412
20 CoreData 0x00000001870d418c -[NSManagedObjectContext save:] + 1260
我无法从这些糟糕的日志中找出问题所在。