上下文不保存更改,错误1550

时间:2013-05-11 15:41:25

标签: objective-c core-data nsmanagedobject nsmanagedobjectcontext

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

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];
    }
}

所以那里没有重复......

3 个答案:

答案 0 :(得分:8)

说明:

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)。

答案 1 :(得分:3)

可可错误1550意味着你有一个“晃来晃去”的指针,更具体地说是一个指向无处的关系的引用......我想你可能会从existinObjectWithID方法中找到一个零?

答案 2 :(得分:0)

我也遇到了1550错误代码。我不小心改变了数据模型 修改了实体中某个关系的目标。确保仔细检查NSValidationErrorObject描述的实体和NSValidationErrorKey描述的关系是否是您想要的实体。