Created
March 25, 2013 20:33
-
-
Save lukeredpath/5240453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have an entity Foo, which has a 1-n relationship with Bar. Bar has a 1-n relationship with Baz. | |
On the main thread, the UI is showing a list of all the Bars in a single Foo. I am using KVO on Foo's bars relationship to detect when Bars are added to Foo. | |
Using a child MOC of the main MOC (the UI uses the main MOC), I create a new Bar, associate it with a couple of Baz objects, then add it to Foo's bars relationship. | |
Then I save the child MOC, which causes its changes to be merged into the main MOC. | |
At this point, my KVO observer on foo.bars fires, and when I inspect the change dictionary, I see my inserted Bar object however, the Bar's bazes relationship is empty! | |
My KVO observer then fires again immediately, and this time, the change dictionary contains my Bar object and its bazes relationship is not empty. | |
Its not valid for Bar to have an empty set of Baz objects, but as I'm trying to refresh my UI in response to these KVO notifications, at the point the first KVO notification fires, I'm trying to refresh my UI to display an invalid Bar. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I fixed it. The thing is: you want to save your new Widget before adding the relationship to your Inventory: