0

I am using CKSIncrementalStore.

My datamodel is: DataModel

All attributes are optional.

I can create a client and after that create a project where I add the client as a relation.

Like this:

    project.client = client

It works fine as long as I only add the same client to one project. Every time I try to add a client to more than one project it gives me this error:

Error Domain=NSCocoaErrorDomain Code=1550 "The operation couldn’t be completed. (Cocoa error 1550.)" UserInfo=0x1700ff000 {NSValidationErrorObject=<TimeTarget.Client: 0x1742a9d80> (entity: Client; id: 0x1706226c0 <x-coredata://5190F80A-6F0D-453D-9651-D4C827B299B1-2205-0000008CA6B29B34/Client/p6568F8E8-DF69-485C-BE84-B68261BA60F8> ; data: {
billable = 0;
color = 0;
defaultHourRate = 0;
name = Byyy;
projects =     (
    "0x17062c760 <x-coredata:///Project/tFDBB182C-7A2C-4E13-9AC3-080B305B10AB6>",
    "0xd000000000040002 <x-coredata://27D63876-D016-436C-B8DD-99C0B8A9587A/Project/p1>"
); }), NSValidationErrorValue=Relationship 'projects' on managed object (0x1742a9d80) <TimeTarget.Client: 0x1742a9d80> (entity: Client; id: 0x1706226c0 <x-coredata://5190F80A-6F0D-453D-9651-D4C827B299B1-2205-0000008CA6B29B34/Client/p6568F8E8-DF69-485C-BE84-B68261BA60F8> ; data: {
billable = 0;
color = 0;
defaultHourRate = 0;
name = Byyy;
projects =     (
    "0x17062c760 <x-coredata:///Project/tFDBB182C-7A2C-4E13-9AC3-080B305B10AB6>",
    "0xd000000000040002 <x-coredata://27D63876-D016-436C-B8DD-99C0B8A9587A/Project/p1>"
); }) with objects {(
<TimeTarget.Project: 0x1702a2b20> (entity: Project; id: 0x17062c760 <x-coredata:///Project/tFDBB182C-7A2C-4E13-9AC3-080B305B10AB6> ; data: {
billable = 0;
client = "0x1706226c0 <x-coredata://5190F80A-6F0D-453D-9651-D4C827B299B1-2205-0000008CA6B29B34/Client/p6568F8E8-DF69-485C-BE84-B68261BA60F8>";
color = 0;
defaultHourRate = 0;
name = "\U00c5\U00e5\U00e5\U00e5";
}),
<TimeTarget.Project: 0x1700dd730> (entity: Project; id: 0xd000000000040002 <x-coredata://27D63876-D016-436C-B8DD-99C0B8A9587A/Project/p1> ; data: {
billable = 0;
"cks_LocalStore_Attribute_ChangeType" = 0;
"cks_LocalStore_Attribute_EncodedValues" = <62706c69 73743030 d4010203 04050649 4a582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f70>;
"cks_LocalStore_Attribute_RecordID" = "F8288FC8-8CBC-4B19-B2A5-F0FD8C19F109";
client = "0xd000000000040000 <x-coredata://27D63876-D016-436C-B8DD-99C0B8A9587A/Client/p1>";
color = 0;
defaultHourRate = 0;
name = Iiii;}) )}, NSValidationErrorKey=projects, NSLocalizedDescription=The operation couldn’t be completed. (Cocoa error 1550.)}

I have the NSManagedObjectContext stored in a sharedManager so I use the same NSManagedObjectContext everywhere.

What might be wrong? :)

  • *"I use the same NSManagedObjectContext everywhere"*: Are you always calling it from the same thread? – Aaron Brager Jul 16 '15 at 18:17
  • I am not using threading, so I assume everything run on mainthread. :) – Nick Emil Starup Pedersen Jul 16 '15 at 18:34
  • This might help http://stackoverflow.com/questions/16498875/context-does-not-save-the-changes-with-error-1550 – Nofel Mahmood Jul 16 '15 at 19:27
  • @NickEmilStarupPedersen I wouldn't assume, since another library might be switching (you can check by logging `[NSThread isMainThread]` before you update your data model) – Aaron Brager Jul 16 '15 at 22:52
  • Other things to check: (1) the objects are actually the type of objects you think they are; (2) you aren't creating any invalid associations (like adding a client to a project that already has a client) – Aaron Brager Jul 16 '15 at 23:07
  • Okay, found out it is main thread. If I call TimeManager.timeManager.managedObjectContext!.insertObject(client) before setting the client to the project. The client get saved on the project. But then every time I do that a new client with all of the projects is also added. – Nick Emil Starup Pedersen Jul 17 '15 at 00:12
  • Okay, I its working until I restart the app, then it gives me this error: 'Cannot retrieve referenceObject from an objectID that was not created by this store'. Do I need to call something on the object before I edit/save it? Like refresh it? And if the clients have projects in NSSet do I need to refresh all of them? (: – Nick Emil Starup Pedersen Jul 17 '15 at 21:28

1 Answers1

0

It was an issue with the library. (:

See: https://github.com/nofelmahmood/CKSIncrementalStore/issues/6