Sometimes while using Core-Data object the app crashes with the error:
CoreData: error: NULL _cd_rawData but the object is not being turned into a fault
Hmmm, some things I would change in that code.
Use the error pointers, that is what they are for. You will probably get a solution just from that. Pass in an NSError
pointer, check the return from the -save:
call and spit out the error to console on a failure.
Your queue management is a little scary. Instead of doing dispatch_async()
, change that to -[NSManagedObjectContext performBlock:]
. That will guarantee you are on the right thread/queue for the context you are accessing. With the way you have written it there is no guarantee and thus maintainability is low.
Once you make those two changes and you are still failing, update your question with the output from the NSError
objects and we can see what is going on.
Even though the error is not happening on the saves, you still want to check that return value and the error as it can give us the missing information.
Please reply here if/when you reproduce the crash.
Ok, that tends to indicate that you are creating objects in different MOCs and then connecting them through a relationship as you gathered already. Can you post or describe how and when you are creating objects? What MOC you are using?
Can you also post your updated code for saving?