I was having problems adding objects to one of my core data objects that has a relationship and after doing some investigating I realized it was because that objects managedObjectContext was nil (0x0). Some more investigating revealed that anytime I created an object of that type, the managedObjectContext was always nil. Every object I create of any other type has the correct managedObjectContext. And no, the object was not deleted, this is immediately after calling NSEntityDescription:insertNewObjectForEntityForName:inManagedObjectContext
Why would only this particular object be broken? It's also strange that even though the managedObjectContext seems to be nil, it otherwise works correctly (other than the relationship problem). I've tried resetting the simulator several times and I've even regenerated the .h and .m files that core data produces for that object but I can't get it to work. As far as I can tell, there are no errors, the managedObjectContext just never gets set.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…