I’m currently taking the iOS Databases (SwiftUI) course, and am applying what I learned from Module 6, lesson 2 to my own project. This is a very data heavy project with 25 entities within the CoreData data model.
Once I added the persistence.swift file to my project per the lesson, it builds fine. But when I then try to run that in the simulator (iPhone 14 Pro) I get the following error in the persistence.swift file:
Thread 1: “currently unsupported (too many keypaths)”
Does anyone know what that is referring to, and where I might fix it?
Upon crash, the console contains the following explanation:
2023-05-20 15:21:37.965434-0700 CaptainsLog[56044:17262889] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'currently unsupported (too many keypaths)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000180437330 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x0000000180051274 objc_exception_throw + 56
2 CoreData 0x000000018440f3e8 -[PFCloudKitImportZoneContext initWithUpdatedRecords:deletedRecordTypeToRecordIDs:options:fileBackedFuturesDirectory:] + 0
3 CoreData 0x00000001845b7c40 __61-[NSSQLEntity_DerivedAttributesExtension _generateTriggerSQL]_block_invoke + 68
4 CoreFoundation 0x0000000180384f04 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 16
5 CoreFoundation 0x000000018038543c ____NSDictionaryEnumerate_block_invoke_2 + 52
6 CoreFoundation 0x000000018046c110 CFBasicHashApply + 140
7 CoreFoundation 0x0000000180385038 __NSDictionaryEnumerate + 188
8 CoreData 0x00000001845b7b38 -[NSSQLEntity_DerivedAttributesExtension _generateTriggerSQL] + 252
9 CoreData 0x0000000184528fb0 -[NSSQLiteConnection createTriggersForEntities:] + 236
10 CoreData 0x0000000184529380 -[NSSQLiteConnection createTablesForEntities:] + 348
11 CoreData 0x0000000184523ce4 -[NSSQLiteConnection connect] + 2940
12 CoreData 0x00000001844f41e4 __32-[NSSQLCore _loadAndSetMetadata]_block_invoke + 92
13 CoreData 0x0000000184526724 __37-[NSSQLiteConnection performAndWait:]_block_invoke + 40
14 libdispatch.dylib 0x0000000103e61d50 _dispatch_client_callout + 16
15 libdispatch.dylib 0x0000000103e738d8 _dispatch_lane_barrier_sync_invoke_and_complete + 144
16 CoreData 0x00000001845261dc -[NSSQLiteConnection performAndWait:] + 132
17 CoreData 0x00000001844f45d4 -[NSSQLCore loadMetadata:] + 228
18 CoreData 0x00000001844bc230 __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 2344
19 CoreData 0x00000001844cad8c gutsOfBlockToNSPersistentStoreCoordinatorPerform + 208
20 libdispatch.dylib 0x0000000103e61d50 _dispatch_client_callout + 16
21 libdispatch.dylib 0x0000000103e738d8 _dispatch_lane_barrier_sync_invoke_and_complete + 144
22 CoreData 0x00000001844b8644 _perform + 176
23 CoreData 0x00000001844bb5dc -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 316
24 CoreData 0x00000001844bad90 -[NSPersistentStoreCoordinator _doAddPersistentStoreWithDescription:privateCopy:completeOnMainThread:withHandler:] + 396
25 CoreData 0x00000001844bb434 -[NSPersistentStoreCoordinator addPersistentStoreWithDescription:completionHandler:] + 200
26 CoreData 0x00000001845b9658 -[NSPersistentContainer _loadStoreDescriptions:withCompletionHandler:] + 180
27 CoreData 0x00000001845b9568 -[NSPersistentContainer loadPersistentStoresWithCompletionHandler:] + 244
28 CaptainsLog 0x000000010291f538 $s11CaptainsLog21PersistenceControllerV8inMemoryACSb_tcfC + 796
29 CaptainsLog 0x000000010291f200 $s11CaptainsLog21PersistenceControllerV6shared_WZ + 20
30 libdispatch.dylib 0x0000000103e61d50 _dispatch_client_callout + 16
31 libdispatch.dylib 0x0000000103e637f8 _dispatch_once_callout + 84
32 CaptainsLog 0x000000010291f67c $s11CaptainsLog21PersistenceControllerV6sharedACvau + 80
33 CaptainsLog 0x0000000102892b60 $s11CaptainsLog0aB3AppVACycfC + 28
34 CaptainsLog 0x0000000102892be8 $s11CaptainsLog0aB3AppV7SwiftUI0C0AadEPxycfCTW + 20
35 SwiftUI 0x0000000108447464 OUTLINED_FUNCTION_16 + 72
36 CaptainsLog 0x0000000102892ad0 $s11CaptainsLog0aB3AppV5$mainyyFZ + 40
37 CaptainsLog 0x0000000102892c08 main + 12
38 dyld 0x0000000103a01514 start_sim + 20
39 ??? 0x0000000103ad5f28 0x0 + 4356661032
40 ??? 0xf535000000000000 0x0 + 17669028713058009088
)
libc++abi: terminating due to uncaught exception of type NSException
(lldb)
If I comment out the 2 persistenceController lines from my app entry file it will run:
import SwiftUI
@main
struct CaptainsLogApp: App {
// let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
MainView()
// .environment(\.managedObjectContext, persistenceController.container.viewContext)
.environmentObject(InventoryModel())
.environmentObject(VesselModel())
.environmentObject(VoyageModel())
Here’s the persistence.swift file:
//
// Persistence.swift
// CaptainsLog
//
// Created by Pete Lorimer on 5/18/23.
//
import CoreData
struct PersistenceController {
static let shared = PersistenceController()
static var preview: PersistenceController = {
let result = PersistenceController(inMemory: true)
let viewContext = result.container.viewContext
for _ in 0..<10 {
let newItem = Inventory(context: viewContext)
newItem.id = UUID()
}
do {
try viewContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
return result
}()
let container: NSPersistentContainer
private init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "CaptainsLog")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
}
}