0

When I update a NSManagedObject and save it, I get an error: The operation couldn’t be completed. (Cocoa error 1560.)

  • the object is already in the database, so in fact I am doing an update when saving it
  • when I save the object prior to modifying it, no error
  • I modify it by setting a property of the object. Using KVP has the same result
  • the original save (the object has been created shortly before) and saving after the update are done all in the main thread. The object is never touched from another thread.

The method validateForUpdate: always returns NO. I am not sure if this method should return YES even if the object has not been changed: if object X is saved without error and then I call validateForUpdate: it returns NO.

Any ideas?

Eimantas
  • 48,927
  • 17
  • 132
  • 168
Clemens
  • 21
  • 3
  • Have a look at this post: http://stackoverflow.com/questions/1283960/iphone-core-data-unresolved-error-while-saving – LombaX Jan 05 '13 at 11:51
  • Thanks! The iteration on detailedErrors helped me out! A relationship attribute was empty but mandatory. I do not understand yet why saving X in the very first place had no errors. It seems lik enot having filled this mandatory attribute was not noticed by CoreData until the first update afterwards. I guess this has to do with caching. Anyway, I can fix my problem now. – Clemens Jan 05 '13 at 12:11

1 Answers1

0

The property you change has constraints on what its value could be. Your update violates them, hence keeping you from persisting invalid changes.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
  • See http://stackoverflow.com/questions/1283960/iphone-core-data-unresolved-error-while-saving and iteration on detailedErros will show what is the actual problem. It was not the updated attribute itself. – Clemens Jan 05 '13 at 12:16