I'm making a note app. sync data use CoreData + CloudKit. Have two Entity named 'Cardbag' And 'Card'.
Cards has a to-one nullify relationship to CardPack named pack.
CardPack has a to-many cascade relationship to Card named cards.
1 on device A, create a CardPack NSManagedObject, save, and wait cloudkit sync to device B.
2 when cardpack synced to device B. on device A, create 500 Cards NSManagedObject, and set card.pack = cardpack, save.
3 device B, see Xcode console, when card records download from cloudkit server started, delete cardpack on device B quickly.
then, crash.
I think things maybe like this: sync system making relationships with pack and cards. I delete pack. system can't find pack NSManagedObject, then crash. but, How can I handle it?
Cards has a to-one nullify relationship to CardPack named pack.
CardPack has a to-many cascade relationship to Card named cards.
follow those STEPS:
1 on device A, create a CardPack NSManagedObject, save, and wait cloudkit sync to device B.
Code Block let cardpack = CardPack(context: Database.viewContext) try! Database.viewContext.obtainPermanentIDs(for: [cardpack]) cardpack.uuid = UUID.simpleID cardpack.name = "test" try! Database.viewContext.save()
2 when cardpack synced to device B. on device A, create 500 Cards NSManagedObject, and set card.pack = cardpack, save.
Code Block Database.viewContext.performAndWait { for i in 0..<500 { let card: Card = Card(context: Database.viewContext) try! Database.viewContext.obtainPermanentIDs(for: [card]) card.uuid = UUID.simpleID card.pack = pack } try! Database.viewContext.save() }
3 device B, see Xcode console, when card records download from cloudkit server started, delete cardpack on device B quickly.
Code Block let context = Database.viewContext context.performAndWait { guard let pack = (try? context.existingObject(with: packMOID)) as? CardPack else { return } context.delete(pack) try? context.save() }
then, crash.
Crash Error:
Code Block * Terminating app due to uncaught exception CoreData: debug: CoreData+CloudKit: -[PFMirroredOneToManyRelationship updateRelationshipValueUsingImportContext:andManagedObjectContext:error:](424): Linking object with record name <CKRecordID: 0x281a8c7c0; recordName=9FFDDFE1-FEB2-45B7-A51F-F95719891BA2, zoneID=com.apple.coredata.cloudkit.zone:defaultOwner> to <CKRecordID: 0x281a8c9c0; recordName=D7930F69-180E-4683-95F3-27CD394FFC91, zoneID=com.apple.coredata.cloudkit.zone:defaultOwner> via pack 2020-09-14 17:27:54.901348+0800 TwinklingCard[740:60405] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]!' * First throw call stack: (0x190f19344 0x190c2ecc0 0x19144f66c 0x195a153c8 0x1959b8a3c 0x195acacb8 0x195a0b650 0x1958d722c 0x195ac93bc 0x195ac92e4 0x195af9488 0x195a0b650 0x104f4b4d8 0x104f5ae14 0x1958d725c 0x195af9084 0x195b4d4d4 0x195af8e38 0x195afab80 0x1959ce1ac 0x195afaad8 0x104f4b4d8 0x104f5ae14 0x195afaa28 0x195af7ed4 0x19606ea10 0x196027418 0x1960226d8 0x1960b6afc 0x104f5a7c4 0x104f4b4d8 0x104f52c20 0x104f53868 0x104f5f270 0x190c21718 0x190c279c8) libc++abi.dylib: terminating with uncaught exception of type NSException * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]!' terminating with uncaught exception of type NSException
I think things maybe like this: sync system making relationships with pack and cards. I delete pack. system can't find pack NSManagedObject, then crash. but, How can I handle it?