What is the best way to handle temporary objects in Core Data? I have seen solutions in which temporary contexts are created, where they are inserted into nil contexts, etc.
However, here is the problem that I see in both of these solutions. I use Core Data for my object model, and in some of my views NSSet objects of the main data are stored. The problem is when the object is stored, the identifier of the object changes, which actually invalidates anything stored in any NSSet, since isEqual and hash are now different. Although I could invalidate an object stored in NSSet, it is often impractical and, of course, not always easy.
Here is what I reviewed:
1) override the isEqual method and hash on NSManagedObject (obviously bad)
2) do not put NSManagedObject in an NSSet (use NSDictionary, where the key is always fixed)
3) use a completely different type for storage in NSSet, where I could correctly implement the isEqual and hash code methods
Does anyone have a better solution for this?
source share