1

我在 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>)";
}

我在某个时候遇到了这个崩溃,那就是我想将我的模型保存ExerciseEventCoreData. 所以我在我的视图中创建了一个这样的新实体: self.ee = [NSEntityDescription insertNewObjectForEntityForName:@"ExerciseEvent" inManagedObjectContext:context]

然后我有 2 个按钮,“保存”和“丢弃”。如果我按“丢弃”,我必须删除该实体,这样我就不会ExerciseEvent在上下文中获得可为空的值。我在视图中这样删除它:

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

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

4

1 回答 1

3

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


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

于 2012-09-21T10:19:44.910 回答