SwiftData/BackingData.swift:669: Fatal error: Unknown Relationship Key - subscription)
Мы начали использовать SwiftData только в MainActor, но эта проблема все еще существует. Это затрагивает не всех наших пользователей, но некоторые из них все еще сталкиваются с этим сбоем. В документации Apple не указано, что следует делать в этом случае, а на форумах представлены только примеры с массивами.
Наши модели выглядят следующим образом:
@Model
public final class ProfileModel {
public static let fetchDescriptor = FetchDescriptor
.self
public enum Gender: Codable {
case female
case male
case other
}
public enum Units: Codable {
case imperial
case metric
}
public enum Eating: Codable {
case empath
case enthusiast
case explorer
case guardian
case harmonizer
case pacifier
case regulator
case stoic
case iosDefault
}
public enum RegistrationSource: Codable {
case iOS
case web
}
public enum NHE: Codable {
case combined
case emotional
case mindless
}
public enum Goal: Codable {
case beHealthier
case energyIncrease
case healthyHabits
case looseWeight
case relationshipsWithFood
}
public enum WeightLossFocus: Codable {
case activity
case healthyHabits
case nutrition
case other
}
@Attribute(.unique)
public let id: String
public let isPaid: Bool
public let eating: Eating
public let registrationSource: RegistrationSource
public let nhe: NHE?
public let firstName: String?
public let lastName: String?
public let gender: Gender?
public let height: String?
public let age: Int?
public let weight: String?
public let targetWeight: String?
public let bmi: String?
public let goal: Goal?
public let units: Units?
public let weightLossFocus: WeightLossFocus?
@Relationship(deleteRule: .cascade)
public var subscription: ProfileSubscriptionModel?
public init(
id: String,
isPaid: Bool,
eating: Eating,
registrationSource: RegistrationSource,
nhe: NHE?,
firstName: String?,
lastName: String?,
gender: Gender?,
height: String?,
age: Int?,
weight: String?,
targetWeight: String?,
bmi: String?,
goal: Goal?,
units: Units?,
weightLossFocus: WeightLossFocus?,
subscription: ProfileSubscriptionModel?
) {
self.id = id
self.isPaid = isPaid
self.eating = eating
self.registrationSource = registrationSource
self.nhe = nhe
self.firstName = firstName
self.lastName = lastName
self.gender = gender
self.height = height
self.age = age
self.weight = weight
self.targetWeight = targetWeight
self.bmi = bmi
self.goal = goal
self.units = units
self.weightLossFocus = weightLossFocus
self.subscription = subscription
}
}
@Model
public final class ProfileSubscriptionModel {
public static let fetchDescriptor = FetchDescriptor.self
public let price: Double
public let currency: String
public let period: Int
public let status: String
public let expirationDate: Date
public let cancelledAt: Date?
public init(price: Double, currency: String, period: Int, status: String, expirationDate: Date, cancelledAt: Date?) {
self.price = price
self.currency = currency
self.period = period
self.status = status
self.expirationDate = expirationDate
self.cancelledAt = cancelledAt
}
}
Вот трассировка стека:
Crashed: NSPersistentStoreCoordinator 0x3033927d0
Crashed: NSPersistentStoreCoordinator 0x3033927d0
0 libswiftCore.dylib 0x398c0 _assertionFailure(_:_:file:line
1 SwiftData 0x9c79c __swift_memcpy9_8 + 11448
2 SwiftData 0x9ea58 __swift_memcpy9_8 + 20340
3 SwiftData 0xa35ec __swift_memcpy9_8 + 39688
4 SwiftData 0x54508 __swift_destroy_boxed_opaque_existential_1Tm + 7180
5 SwiftData 0x55d0c __swift_destroy_boxed_opaque_existential_1Tm + 13328
6 SwiftData 0x5340c __swift_destroy_boxed_opaque_existential_1Tm + 2832
7 SwiftData 0x532d0 __swift_destroy_boxed_opaque_existential_1Tm + 2516
8 Mindea 0x2da9c closure #1 in ProfileModel.subscription.setter + 13 (@__swiftmacro_13StorageBoxAPI12ProfileModelC12subscription18_PersistedPropertyfMa_.swift:13)
9 Mindea 0x32578 partial apply for closure #1 in ProfileModel.subscription.setter + 4333757816 (:4333757816)
10 Mindea 0x35fd0 closure #1 in ProfileModel.subscription.setterpartial apply + 4333772752
11 libswiftObservation.dylib 0x6e9c ObservationRegistrar.withMutation(of:keyPath:_:) + 100
12 Mindea 0x32f50 specialized ProfileModel.init(id:isPaid:eating:registrationSource:nhe:firstName:lastName:gender:height:age:weight:targetWeight:bmi
13 Mindea 0x2df50 ProfileModel.init(id:isPaid:eating:registrationSource:nhe:firstName:lastName:gender:height:age:weight:targetWeight:bmi
14 Mindea 0x5200c specialized ProfileModel.init(_:) + 9 (@__swiftmacro_10StorageBox13ModelSchemeV1O011UserProfileC0C15weightLossFocus18_PersistedPropertyfMa_.swift:9)
15 Mindea 0x3df68 closure #1 in variable initialization expression of static MigrationPlan.migrateV1toV2 + 26 (MigrationPlan.swift:26)
16 SwiftData 0x4d63c __swift_destroy_boxed_opaque_existential_0Tm + 114548
17 SwiftData 0x4d584 __swift_destroy_boxed_opaque_existential_0Tm + 114364
18 SwiftData 0x89c4 _swift_stdlib_malloc_size + 6980
19 SwiftData 0xe364 objectdestroyTm + 120
20 CoreData 0x105c3c closure #1 in NSCustomMigrationStage.willMigrateHandler.setter + 44
21 CoreData 0x105ccc partial apply for closure #1 in NSCustomMigrationStage.didMigrateHandler.setter + 20
22 CoreData 0x10571c thunk for @escaping @callee_guaranteed (@guaranteed NSStagedMigrationManager, @guaranteed NSCustomMigrationStage, @unowned AutoreleasingUnsafeMutablePointer?) -> (@unowned Bool) + 88
23 CoreData 0x186bb0 __70-[NSPersistentStoreCoordinator applyMigrationStage:withContext:error:]_block_invoke_2 + 116
24 CoreData 0x1868e8 -[NSPersistentStoreCoordinator createPersistentContainerForMigrationContext:withModel:andExecuteBlock:] + 480
25 CoreData 0x1862cc -[NSPersistentStoreCoordinator applyMigrationStage:withContext:error:] + 1516
26 CoreData 0x182c50 -[NSPersistentStoreCoordinator migrateStoreWithContext:error:] + 1040
27 CoreData 0xc666c __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 3672
28 CoreData 0x1e87c gutsOfBlockToNSPersistentStoreCoordinatorPerform + 204
29 libdispatch.dylib 0x3dd4 _dispatch_client_callout + 20
30 libdispatch.dylib 0x132c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
31 CoreData 0x11cb4 _perform + 176
32 CoreData 0xc54a8 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 424
33 CoreData 0xdc44c -[NSPersistentStoreCoordinator _doAddPersistentStoreWithDescription:privateCopy:completeOnMainThread:withHandler:] + 400
34 CoreData 0xdc1f0 -[NSPersistentStoreCoordinator addPersistentStoreWithDescription:completionHandler:] + 228
35 CoreData 0xdca1c -[NSPersistentContainer _loadStoreDescriptions:withCompletionHandler:] + 184
36 CoreData 0xdbcc0 -[NSPersistentContainer loadPersistentStoresWithCompletionHandler:] + 248
37 CoreData 0x224f10 -[NSPersistentContainer(CoreDataSPI) load:] + 240
38 SwiftData 0xd10c _swift_stdlib_malloc_size + 25228
39 SwiftData 0x78e0 _swift_stdlib_malloc_size + 2656
40 SwiftData 0xe0c8 _swift_stdlib_malloc_size + 29256
41 SwiftData 0x7510 _swift_stdlib_malloc_size + 1680
42 SwiftData 0xfb20 block_destroy_helper + 4120
43 SwiftData 0xf178 block_destroy_helper + 1648
44 Mindea 0x3b9e4 DataBaseManager.init(loggerManager:) + 35 (DataBaseManager.swift:35)
45 Mindea 0x12608 closure #1 in NewDependencyContainer.registerStorageBox() + 14 (DependencyContainer+StorageBox.swift:14)
46 Mindea 0xadbc specialized closure #1 in NewDependencyContainer.register(scope
47 Mindea 0x1042c specialized NewDependencyContainer.resolveDependency() + 4333618220
48 Mindea 0x12680 closure #2 in NewDependencyContainer.registerStorageBox() + 4333627008
49 Mindea 0xa9d8 specialized closure #1 in NewDependencyContainer.register(scope
50 Mindea 0x16908 NewDependencyContainer.resolveDependency() + 50 (NewDependencyContainer.swift:50)
51 Mindea 0x16868 protocol witness for Resolver.resolveDependency() in conformance NewDependencyContainer + 4333643880 (:4333643880)
52 Mindea 0xefdd64 Container.resolveDependency() + 63 (Container.swift:63)
53 Mindea 0xefe09c protocol witness for Resolver.resolveDependency() in conformance Container + 4349272220 (:4349272220)
54 Mindea 0x8948 closure #1 in DependencyContainer.registerUserSettingsFlowData() + 19 (DependencyContainer+UserSettingsFlowData.swift:19)
55 Mindea 0xefdb7c closure #1 in Container.register(scope
56 Mindea 0xefdcc4 Container.resolveDependency() + 60 (Container.swift:60)
57 Mindea 0xc368 partial apply for closure #1 in AppDelegate.init() + 4333601640
58 Mindea 0xadbc specialized closure #1 in NewDependencyContainer.register(scope
59 Mindea 0xc2c4 partial apply for specialized closure #1 in NewDependencyContainer.register(scope
60 Mindea 0x1042c specialized NewDependencyContainer.resolveDependency() + 4333618220
61 Mindea 0x10e04 closure #1 in NewDependencyContainer.registerNetworkBox() + 25 (DependencyContainer+NetworkBox.swift:25)
62 Mindea 0xa9d8 specialized closure #1 in NewDependencyContainer.register(scope
63 Mindea 0xc1e4 partial apply for specialized closure #1 in NewDependencyContainer.register(scope
64 Mindea 0x16908 NewDependencyContainer.resolveDependency() + 50 (NewDependencyContainer.swift:50)
65 Mindea 0x16868 protocol witness for Resolver.resolveDependency() in conformance NewDependencyContainer + 4333643880 (:4333643880)
66 Mindea 0xefdd64 Container.resolveDependency() + 63 (Container.swift:63)
67 Mindea 0xefe09c protocol witness for Resolver.resolveDependency() in conformance Container + 4349272220 (:4349272220)
68 Mindea 0xeffe6c ViewModelContainer.resolveDependency() + 58 (ViewModelContainer.swift:58)
69 Mindea 0xefe09c protocol witness for Resolver.resolveDependency() in conformance Container + 4349272220 (:4349272220)
70 Mindea 0x80348 closure #1 in ViewModelContainer.registerAppFlow() + 4334076744 (RemoteProfileUseCaseRepository.swift:4334076744)
71 Mindea 0xefeb34 partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed Resolver) -> (@out A) + 4349274932 (:4349274932)
72 Mindea 0xefdcc4 Container.resolveDependency() + 60 (Container.swift:60)
73 Mindea 0xf00e18 ViewModelFactory.build() + 21 (ViewFactory.swift:21)
74 Mindea 0x12888 closure #1 in MindeaApp.body.getter + 24 (MindeaApp.swift:24)
75 SwiftUI 0x427bc0 OUTLINED_FUNCTION_283 + 626180
76 Mindea 0x13708 protocol witness for App.body.getter in conformance MindeaApp + 22 (MindeaApp.swift:22)
77 SwiftUI 0x412a84 OUTLINED_FUNCTION_283 + 539848
78 SwiftUI 0x24d738 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 31980
79 SwiftUI 0x24b3bc -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 22896
80 SwiftUI 0x1fdb30 dynamic_cast_existential_0_superclass_conditional + 5492
81 AttributeGraph 0x9010 AG::Graph::UpdateStack::update() + 512
82 AttributeGraph 0x8bfc AG::Graph::update_attribute(AG::data::ptr, unsigned int) + 424
83 AttributeGraph 0x2cc0 AG::Graph::input_value_ref_slow(AG::data::ptr, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) + 720
84 AttributeGraph 0x2854 AGGraphGetValue + 228
85 SwiftUI 0x1fefd8 dynamic_cast_existential_0_superclass_conditional + 10780
86 SwiftUI 0x1feeec dynamic_cast_existential_0_superclass_conditional + 10544
87 SwiftUI 0x1fea4c dynamic_cast_existential_0_superclass_conditional + 9360
88 SwiftUI 0x1fdb30 dynamic_cast_existential_0_superclass_conditional + 5492
89 AttributeGraph 0x9010 AG::Graph::UpdateStack::update() + 512
90 AttributeGraph 0x8bfc AG::Graph::update_attribute(AG::data::ptr, unsigned int) + 424
91 AttributeGraph 0x2cc0 AG::Graph::input_value_ref_slow(AG::data::ptr, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) + 720
92 AttributeGraph 0x2854 AGGraphGetValue + 228
93 SwiftUI 0x408d1c OUTLINED_FUNCTION_283 + 499552
94 SwiftUI 0x134ef8 OUTLINED_FUNCTION_164 + 43160
95 SwiftUI 0x1fdb30 dynamic_cast_existential_0_superclass_conditional + 5492
96 AttributeGraph 0x9010 AG::Graph::UpdateStack::update() + 512
97 AttributeGraph 0x8bfc AG::Graph::update_attribute(AG::data::ptr, unsigned int) + 424
98 AttributeGraph 0xfef8 AG::Graph::value_ref(AG::AttributeID, unsigned int, AGSwiftMetadata const*, unsigned char&) + 288
99 AttributeGraph 0x28a4 AGGraphGetValue + 308
100 SwiftUI 0x39e768 OUTLINED_FUNCTION_283 + 63916
101 SwiftUI 0x133618 OUTLINED_FUNCTION_164 + 36792
102 SwiftUI 0x10d350 OUTLINED_FUNCTION_831 + 8884
103 SwiftUI 0x407078 OUTLINED_FUNCTION_283 + 492220
104 UIKitCore 0x19acc0 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1080
105 UIKitCore 0x442d28 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 808
106 UIKitCore 0x2ff94c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 360
107 UIKitCore 0x2ff600 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 288
108 FrontBoardServices 0x1a974 -[FBSScene _callOutQueue_didCreateWithTransitionContext:completion:] + 324
109 FrontBoardServices 0x1a808 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.108 + 280
110 FrontBoardServices 0x166cc -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168
111 FrontBoardServices 0x1acc4 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 352
112 libdispatch.dylib 0x3dd4 _dispatch_client_callout + 20
113 libdispatch.dylib 0x786c _dispatch_block_invoke_direct + 288
114 FrontBoardServices 0x17d58 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52
115 FrontBoardServices 0x17cd8 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240
116 FrontBoardServices 0x17bb0 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28
117 CoreFoundation 0x56834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
118 CoreFoundation 0x567c8 __CFRunLoopDoSource0 + 176
119 CoreFoundation 0x542f8 __CFRunLoopDoSources0 + 340
120 CoreFoundation 0x53484 __CFRunLoopRun + 828
121 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608
122 GraphicsServices 0x11a8 GSEventRunModal + 164
123 UIKitCore 0x40a90c -[UIApplication _run] + 888
124 UIKitCore 0x4be9d0 UIApplicationMain + 340
125 SwiftUI 0x3f4148 OUTLINED_FUNCTION_283 + 414604
126 SwiftUI 0x3a0714 OUTLINED_FUNCTION_283 + 72024
127 SwiftUI 0x3ac4d0 OUTLINED_FUNCTION_283 + 120596
128 Mindea 0x13860 main + 4333631584 (MindeaApp.swift:4333631584)
129 ??? 0x1b4249e4c (Missing)
Thread
0 libsystem_pthread.dylib 0x10c4 start_wqthread + 8281768130
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x1808 mach_msg2_trap + 8
1 libsystem_kernel.dylib 0x5008 mach_msg2_internal + 80
2 libsystem_kernel.dylib 0x4f20 mach_msg_overwrite + 436
3 libsystem_kernel.dylib 0x4d60 mach_msg + 24
4 CoreFoundation 0x53f5c __CFRunLoopServiceMachPort + 160
5 CoreFoundation 0x53600 __CFRunLoopRun + 1208
6 CoreFoundation 0x52cd8 CFRunLoopRunSpecific + 608
7 Foundation 0xc7e4c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8 Foundation 0xc7c9c -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9 UIKitCore 0x41e640 -[UIEventFetcher threadMain] + 420
10 Foundation 0xde718 __NSThread__start__ + 732
11 libsystem_pthread.dylib 0x606c _pthread_start + 136
12 libsystem_pthread.dylib 0x10d8 thread_start + 8
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
com.google.fira.worker
0 libsystem_kernel.dylib 0x7d0c __ulock_wait + 8
1 libdispatch.dylib 0x47c4 _dlock_wait + 56
2 libdispatch.dylib 0x4578 _dispatch_thread_event_wait_slow + 56
3 libdispatch.dylib 0x135b0 __DISPATCH_WAIT_FOR_QUEUE__ + 368
4 libdispatch.dylib 0x1315c _dispatch_sync_f_slow + 148
5 Mindea 0x146f488 -[APMIdentity identifierForVendor] + 4354978952
6 Mindea 0x1485af0 APMUpdateConsentSignalsAndIdentifiers + 4355070704
7 Mindea 0x148b634 -[APMMeasurement(Event) createRawEventMetadataWithUserAttributes:] + 4355094068
8 Mindea 0x148d334 -[APMMeasurement(Event) writeEvent:isPublicEvent:isRealtime:] + 4355101492
9 Mindea 0x148b0e8 __57-[APMMeasurement(Event) writeFilteredEventOnWorkerQueue:]_block_invoke + 4355092712
10 Mindea 0x14da0d4 -[APMSqliteStore performTransactionWithError:block:] + 4355416276
11 Mindea 0x1451e7c -[APMDatabase performTransaction:] + 4354858620
12 Mindea 0x148ae3c -[APMMeasurement(Event) writeFilteredEventOnWorkerQueue:] + 4355092028
13 Mindea 0x148aba4 -[APMMeasurement(Event) writeEventOnWorkerQueue:] + 4355091364
14 Mindea 0x148a77c -[APMMeasurement(Event) handleEventOnWorkerQueue:] + 4355090300
15 Mindea 0x148a490 -[APMMeasurement(Event) handleInternalEventOnWorkerQueue:] + 4355089552
16 Mindea 0x147ad58 -[APMMeasurement reportSessionStartOnWorkerQueueWithTimestamp:appInBackground:] + 4355026264
17 Mindea 0x147b1e4 -[APMMeasurement reportFirstOpenOnWorkerQueue] + 4355027428
18 Mindea 0x147a6d0 __47-[APMMeasurement startMeasurementOnWorkerQueue]_block_invoke + 4355024592
19 Mindea 0x147a0dc -[APMMeasurement startMeasurementOnWorkerQueue] + 4355023068
20 Mindea 0x1479940 -[APMMeasurement setEnabledOnWorkerQueue:] + 4355021120
21 Mindea 0x1479858 __29-[APMMeasurement setEnabled:]_block_invoke + 4355020888
22 Mindea 0x14d1114 __51-[APMScheduler scheduleOnWorkerQueueBlockID:block:]_block_invoke + 4355379476
23 libdispatch.dylib 0x213c _dispatch_call_block_and_release + 32
24 libdispatch.dylib 0x3dd4 _dispatch_client_callout + 20
25 libdispatch.dylib 0xb400 _dispatch_lane_serial_drain + 748
26 libdispatch.dylib 0xbf30 _dispatch_lane_invoke + 380
27 libdispatch.dylib 0x16cb4 _dispatch_root_queue_drain_deferred_wlh + 288
28 libdispatch.dylib 0x16528 _dispatch_workloop_worker_thread + 404
29 libsystem_pthread.dylib 0x4934 _pthread_wqthread + 288
30 libsystem_pthread.dylib 0x10cc start_wqthread + 8
Thread
0 libsystem_kernel.dylib 0x1590 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x4980 _pthread_wqthread + 364
2 libsystem_pthread.dylib 0x10cc start_wqthread + 8
com.google.firebase.crashlytics.MachExceptionServer
0 Mindea 0x128463c FIRCLSProcessRecordAllThreads + 392 (FIRCLSProcess.c:392)
1 Mindea 0x1284a1c FIRCLSProcessRecordAllThreads + 423 (FIRCLSProcess.c:423)
2 Mindea 0x1292b50 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3 Mindea 0x1293354 FIRCLSMachExceptionServer + 523 (FIRCLSMachException.c:523)
4 libsystem_pthread.dylib 0x606c _pthread_start + 136
5 libsystem_pthread.dylib 0x10d8 thread_start + 8
Подробнее здесь: https://stackoverflow.com/questions/786 ... onship-key