3

我正在尝试更新实体并保存更改。我总是收到以下错误:

The operation couldn’t be completed. (Cocoa error 1550.)

方法:

- (BOOL) updateEvent:(EventDTO*)eventDTO{
    BOOL saved = YES;

    [self getDataCoreContext];

    if (context) {
        NSError *error;

        Event *myEvent = (Event *)[context existingObjectWithID:eventDTO.entitysID error:&error];

        myEvent.name = eventDTO.name;
        myEvent.descrptn = eventDTO.description;
        myEvent.date = eventDTO.date;
        myEvent.locLatitude = [eventDTO getLatidude];
        myEvent.locLongitude = [eventDTO getLongitude];
        myEvent.numberOfInvited= [NSNumber numberWithInteger:[eventDTO.invitedMembers count]];

        for (User *invUser in eventDTO.invitedMembers) {
            [myEvent addInvitedUsersObject:invUser];
        }

        for (User *accUser in eventDTO.acceptedMembers) {
            [myEvent addAcceptedUsersObject:accUser];
        }

        myEvent.createdBy = (User*)[context existingObjectWithID:eventDTO.creator.objectID error:&error];

        if (![context save:&error]) {
            NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
            saved = NO;
        }
    }
    return saved;
}

它真的让我很困惑,因为我不明白问题是什么..我也试图获取对象并修改它。但同样的错误。

任何解释或提示都会很棒。

编辑(完整的错误对象)1:

ERROR: Error Domain=NSCocoaErrorDomain Code=1550 "The operation couldn’t be completed. (Cocoa error 1550.)" UserInfo=0x14a00130 {NSValidationErrorObject=<Event: 0x11024aa0> (entity: Event; id: 0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8> ; data: {
    acceptedUsers =     (
    );
    createdBy = "0x11024ae0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p1>";
    date = "2013-05-11 16:15:09 +0000";
    descrptn = Auauuauau;
    invitedUsers =     (
        "0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3>",
        "0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6>",
        "0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4>",
        "0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2>",
        "0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5>"
    );
    locLatitude = "51.45373916625977";
    locLongitude = "7.264190196990967";
    name = lALLALLa;
    numberOfInvited = 5;
}), NSValidationErrorKey=invitedUsers, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1550.), NSValidationErrorValue=Relationship 'invitedUsers' on managed object (0x11024aa0) <Event: 0x11024aa0> (entity: Event; id: 0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8> ; data: {
    acceptedUsers =     (
    );
    createdBy = "0x11024ae0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p1>";
    date = "2013-05-11 16:15:09 +0000";
    descrptn = Auauuauau;
    invitedUsers =     (
        "0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3>",
        "0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6>",
        "0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4>",
        "0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2>",
        "0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5>"
    );
    locLatitude = "51.45373916625977";
    locLongitude = "7.264190196990967";
    name = lALLALLa;
    numberOfInvited = 5;
}) with objects {(
    <User: 0x110accb0> (entity: User; id: 0x11069cd0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p3> ; data: {
    acceptedEvents = "<relationship fault: 0x97084a0 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x97017b0 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Daniel Higgins";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "555-478-7672";
    realName = "Daniel Higgins";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110d0e10> (entity: User; id: 0x1104da60 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p6> ; data: {
    acceptedEvents = "<relationship fault: 0x14aa0850 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x13c0f290 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Hank Zakroff";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "(555) 766-4823";
    realName = "Hank Zakroff";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110ad1a0> (entity: User; id: 0x1104da40 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p4> ; data: {
    acceptedEvents = "<relationship fault: 0x16632850 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x16632890 'createdEvents'>";
    deviceInfo = nil;
    displayName = "John Appleseed";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "888-555-5512";
    realName = "John Appleseed";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110b3220> (entity: User; id: 0x110687a0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p2> ; data: {
    acceptedEvents = "<relationship fault: 0x110f50f0 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x16628a60 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Kate Bell";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "(555) 564-8583";
    realName = "Kate Bell";
    status = "WAZZUUP?!";
    userID = nil;
}),
    <User: 0x110ace30> (entity: User; id: 0x1104da50 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/User/p5> ; data: {
    acceptedEvents = "<relationship fault: 0x1a4c6350 'acceptedEvents'>";
    createdEvents = "<relationship fault: 0x1a4c6390 'createdEvents'>";
    deviceInfo = nil;
    displayName = "Anna Haro";
    invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );
    memberShipDetails = nil;
    phoneNumber = "555-522-8243";
    realName = "Anna Haro";
    status = "WAZZUUP?!";
    userID = nil;
})
)}}

编辑2:

根据@Sulthan 的精彩解释,我发现了问题。

在我的 for 循环中,我必须检查该用户是否已存在于该事件中:

for (User *invUser in eventDTO.invitedMembers) {
    BOOL existsInInvitedList = [[eventDTO.invitedMembers valueForKeyPath:@"objectID"] containsObject:invUser.objectID];
    if (!existsInInvitedList) {
        [myEvent addInvitedUsersObject:invUser];
    }
}


for (User *accUser in eventDTO.acceptedMembers) {
    BOOL existsInAcceptedList = [[eventDTO.acceptedMembers valueForKeyPath:@"objectID"] containsObject:accUser.objectID];
    if (!existsInAcceptedList) {
        [myEvent addAcceptedUsersObject:accUser];
    }
}

所以那里没有重复..

4

3 回答 3

9

解释:

NSValidationErrorObject=<Event: 0x11024aa0> ...

这是您尝试保存且验证失败的对象

NSValidationErrorKey=invitedUsers

这是验证失败的属性(关系)

NSValidationErrorValue=Relationship 'invitedUsers' on managed object (0x11024aa0)

什么验证失败。其他一切都是关系中的用户列表......

我不知道您的对象模型,但例如以下内容似乎是错误的:

invitedToEvents =     (
        "0x110abbb0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x166c0840 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p8>",
        "0x110abba0 <x-coredata://9F88714B-84EC-4E8F-9BC4-78E365A8FE0A/Event/p5>"
    );

请注意,其中一个事件存在两次(它具有相同的对象 ID)。

于 2013-05-11T17:46:01.927 回答
3

Cocoa 错误 1550 意味着您有一个“悬空”指针,更具体地说是对指向无处的关系的引用...我假设您可能从其中一种existinObjectWithID方法中得到 nil ?

于 2013-05-11T16:01:36.973 回答
0

我也遇到了 1550 错误代码。我不小心更改了数据模型并修改了实体中关系之一的目的地。确保仔细检查 NSValidationErrorObject 描述的实体和 NSValidationErrorKey 描述的关系是你想要的。

于 2014-01-14T10:31:48.277 回答