gpt4 book ai didi

iOS - Unresolved 错误导致崩溃 : Dangling reference to an invalid object

转载 作者:行者123 更新时间:2023-11-29 11:08:47 25 4
gpt4 key购买 nike

我在 iOS 上遇到以下崩溃:

    Unresolved error Error Domain=NSCocoaErrorDomain Code=1550 "The operation couldn’t be completed. (Cocoa error 1550.)" UserInfo=0x74a30d0 {NSValidationErrorObject=<Exercise: 0x9097d50> (entity: Exercise; id: 0x9097970 <x-coredata://AF762754-4CD9-4386-A453-049CC8710DBF/Exercise/p124> ; data: {
groupId = 21;
id = 102;
intensity = "0x906a7a0 <x-coredata://AF762754-4CD9-4386-A453-049CC8710DBF/Intensity/p125>";
lengthMeasurable = 1;
name = Running;
owner = "0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4>";
picId = 2719;
}), NSAffectedObjectsErrorKey=(
"<ExerciseEvent: 0x9090910> (entity: ExerciseEvent; id: 0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4> ; data: <fault>)"
), Dangling reference to an invalid object.=null, NSValidationErrorKey=owner, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1550.), NSValidationErrorValue=<ExerciseEvent: 0x9090910> (entity: ExerciseEvent; id: 0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4> ; data: <fault>)}, {
"Dangling reference to an invalid object." = "<null>";
NSAffectedObjectsErrorKey = (
"<ExerciseEvent: 0x9090910> (entity: ExerciseEvent; id: 0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4> ; data: <fault>)"
);
NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1550.)";
NSValidationErrorKey = owner;
NSValidationErrorObject = "<Exercise: 0x9097d50> (entity: Exercise; id: 0x9097970 <x-coredata://AF762754-4CD9-4386-A453-049CC8710DBF/Exercise/p124> ; data: {\n groupId = 21;\n id = 102;\n intensity = \"0x906a7a0 <x-coredata://AF762754-4CD9-4386-A453-049CC8710DBF/Intensity/p125>\";\n lengthMeasurable = 1;\n name = Running;\n owner = \"0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4>\";\n picId = 2719;\n})";
NSValidationErrorValue = "<ExerciseEvent: 0x9090910> (entity: ExerciseEvent; id: 0x9096540 <x-coredata:///ExerciseEvent/t6817E9A9-9A4C-4044-BF20-FC15380B7C2F4> ; data: <fault>)";
}

我在某个时刻遇到了这个崩溃,那是当我想在 CoreData 中保存我的模型 ExerciseEvent 时。所以我在我看来创建了一个像这样的新实体:self.ee = [NSEntityDescription insertNewObjectForEntityForName:@"ExerciseEvent"inManagedObjectContext:context]

然后我有 2 个按钮,“保存”和“丢弃”。如果我按“放弃”,我必须删除该实体,这样我就不会在上下文中得到可为 null 的 ExerciseEvent。我在 View 中是这样删除的:

[context deleteObject:self.ee];
[context save:nil];

然后,当我打开所有 ExerciseEvents 的列表时,我会遇到如上所述的以下崩溃。

最佳答案

出现此错误的原因通常是当 Excercise 对象与 ExerciseEvent 没有必要的相互关系时,关系设置不当。您正在尝试删除对象 ExerciseEvent。而Exercise对象和这个ExerciseEvent是有关系的,不能和这个有空关系,但是当你移除ExerciseEvent时,会出现错误。该对象是“悬垂的”,因为对象图说它应该处于一种关系中,但它只是悬在空间中,与任何其他对象无关。


因此您需要做的是在对象 ExerciseEvent 和 Exercise 之间设置正确的关系删除规则。应该有级联规则。您可以在此处找到详细信息:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html

关于iOS - Unresolved 错误导致崩溃 : Dangling reference to an invalid object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12527679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com