Re: Data not retained in document based core data app with cocoa bindings
Re: Data not retained in document based core data app with cocoa bindings
- Subject: Re: Data not retained in document based core data app with cocoa bindings
- From: Jerry Krinock <email@hidden>
- Date: Sat, 10 Oct 2015 21:22:12 -0700
Hello, Devarshi.
I think that adding the Document to your storyboard was a mistake. To prove that, log self to console in Document's init function, and you will see that, when one document opens, *two* Document objects get created. Your user interface is bound to one, and the persistent store is connected to the other one. So that explains why changes made in your user interface do not persist.
So you should delete that Document from your storyboard. Then, note that, in Document’s instantiateControllerWithIdentifier() function, a window controller with identifier "Document Window Controller” is instantiated and in the storyboard, in the Window Controller, in the Identity Inspector, Xcode has cleverly set the Storyboard ID to the same string, "Document Window Controller”. So it looks to me as if things would work if you could bind your array controller’s managedObjectContext the window controller with key path document.managedObjectContext. Unfortunately, Xcode does not offer that choice; I presume because Cocoa Bindings do not work across scenes?
The instantiateControllerWithIdentifier() will also allow you to instantiate a view controller instead of a window controller. So I suppose that you could subclass NSViewController, add a ‘document’ property to it, set it to self in instantiateControllerWithIdentifier(), and then you could bind to document.managedObjectContext, as desired.
But that seems like an awful lot of trouble to go through for what should be a quite normal document-based app. Someone please tell us the correct way to make this binding :)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden