I’m getting a Cocoa error 1570 while trying to store data in a core data object that has a to-many relationship.
There error from the log file:
2012-05-25 12:02:38.919 TestProject[5059:12e03] DetailedError: {
NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1570.)";
NSValidationErrorKey = conversation;
NSValidationErrorObject = "<Messages: 0x933e190> (entity: Messages; id: 0x933e1d0 <x-coredata:///Messages/tF3A62C22-456B-41EB-B9A4-0BA1E6738A6337> ; data: {\n conversation = nil;\n conversationID = nil;\n createdAt = nil;\n messageID = nil;\n nickname = nil;\n originNetwork = nil;\n text = nil;\n timestamp = nil;\n userImageURL = nil;\n})";
}
The specific relationship is Conversations<—>>Messages, or one conversation can have multiple messages, and each message belongs to exactly one conversation.
In my model, both of these NSManagedObjects are optional.
My question is, how do I properly store a message object in conversation?
I know it has something to do with sets, but I have yet to implement it properly.
Any and all specific or abstract code-snippets would be much appreciated!
Thanks!
It depends on whether you’re using NSManagedObject subclasses or not. If you are (I like to do this), you’d have a
ASConversationandASMessageclass (prefixes being whatever), then you have Xcode auto-generate them for you, and you can use something like:Provided you have the inverse relationship set up correctly from
Messageback toConversationas a to-one, all should be set up for you when you sendsaveto themoc.If you don’t have subclasses, you’d have to use the generic way, a bit more of a pain IMHO.
Then save as before. Do check that you have optional also set on the relationship – cocoa error 1570 is “mandatory value not set” – but it can apply to relationships too.