Build environment: Xcode 7 beta 7 OS X: 10.10.5 Swift 2
I have a project that is using the BSManagedDocument class from github to wrap core data into an NSDocument. I am using Cocoa bindings to get the data from core data to an NSOutlineView using an NSTree Controller.
The object model is fairly simple. The object (called SourceGroup_ tied to the tree controller has a one-to-many relationship with itself to provide the hierarchical data for the tree controller. It also has an optional one-to-one relationship with a Media object that provides a URL for associated media (image, video, etc.).
The outline view has three columns bound, two are bound to properties of the main object while the third is a thumbnail image that comes from the one-to-one media relationship.
Everything displays fine but someitmes when I close the document I get an EXC_BAD_ACCESS in _NSGetUsingKeyValueGetter that goes back though NSAutoUnbinder and [NSTableCellView release] back through [NSAutoreleasePool drain]. This doesn't happen every time but it does happen occasionally.
It I remove the column that is bound through the one-to-one relationship it never crashes. If I add in a non-core data property on SourceGroup that simply returns the image from the preferredMedia relationship and then bind to that property on SourceGroup, it never crashes.
It doesn't matter what the type of the field is. If I bind through the relationship, it (sometimes) crashes on close, whether it's String or NSImage.
I've even tried generating my core data objects as Objective C rather than Swift but that made no difference in behavior. No matter what I change the one constant is that if I bind the view in the table column through the relationship it sometimes crashes on close. Yet, on the detail side, if I bind to the same fields through the selectionIndex that works fine and never crashes. The crash only occurs if it's in the outline view.
I know the descriptions can be a bit vague so I prepared some screenshots unfortunately I appear to lack enough reputation to share them. I'll try to describe the setup.
The tree controller is in entity mode with the entity set to SourceGroup. It's source descriptors and managed object context are bound to my view controller.
The outline view's content is bound to the tree controller's arrangedObjects controller key. The selectionIndexPaths and sort descriptors are also bound to the tree controller.
The value for the NSImageView in the column is bound to the table cell view with the model key path set to objectValue.preferredMedia.thumbnail.
This all displays properly but causes intermittent problems on closing the document. If I put a thumbnail image property into SourceGroup and then bind that image view to objectValue.thumbnail I never see the issue
I don't see anything in the docs about this type of setup being a problem but I'm also new enough to OS X programming that I may have missed something.
Can anyone see a problem in what I'm trying to do?
I had a similar problem with Core Data, treecontroller and images. The managed object context is released before the outlineview and treecontroller. The context is turning managed objects into faults before the bindings remove their observers. A workaround is setting the content of the treecontroller to nil when the window will close.